Browse Source

Merge remote-tracking branch 'remotes/origin/dev_more_appid' into dev

dev_shibei_match
jianjun 5 years ago
parent
commit
f2b72223a1
  1. 99
      epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java
  2. 55
      epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/CustomerAppRedisDTO.java
  3. 4
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerAppController.java
  4. 2
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppService.java
  5. 33
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppServiceImpl.java

99
epmet-auth/src/main/java/com/epmet/redis/CustomerAppWxServiceUtil.java

@ -13,9 +13,9 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAppDTO;
import com.epmet.dto.CustomerAppRedisDTO;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
@ -31,7 +31,6 @@ import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 客户app Redis
@ -50,75 +49,69 @@ public class CustomerAppWxServiceUtil implements ApplicationRunner {
private final static String JSON_STR = "JSON";
@Autowired
private RedisUtils redisUtils;
@Autowired
private RedisTemplate<String,String> redisTemplate;
private RedisTemplate redisTemplate;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
private static Map<String, WxMaService> maServices = Maps.newHashMap();
private static Map<String, WxMaService> maServices = Maps.newConcurrentMap();
public static WxMaService getWxMaService(String appId) {
WxMaService wxMaService = maServices.get(appId);
if (wxMaService == null){
logger.error("getMaService appId:{} is not config from customer_app",appId);
if (wxMaService == null) {
logger.error("getMaService appId:{} is not config from customer_app", appId);
}
return wxMaService;
}
/*public String get(String appId) {
String key = RedisKeys.getAppSecretKey(appId);
String secret = (String) redisUtils.get(key);
if (StringUtils.isBlank(secret)) {
CustomerAppSecretFormDTO param = new CustomerAppSecretFormDTO();
param.setAppId(appId);
Result<String> result = operCrmOpenFeignClient.getSecretByAppId(param);
if (result.success()) {
secret = result.getData();
if (StringUtils.isNotBlank(secret)) {
redisUtils.set(key, secret, MINUTE_THIRTY_EXPIRE);
}
}
}
return secret;
}*/
@Override
public void run(ApplicationArguments args) {
Map<String, WxMaService> maServicesNew = Maps.newConcurrentMap();
SetOperations appSet = null;
List<CustomerAppDTO> result = null;
String appKey = RedisKeys.getCustomerAppKey();
try {
appSet = redisTemplate.opsForSet();
Set<CustomerAppRedisDTO> members = appSet.members(appKey);
if (!CollectionUtils.isEmpty(members)) {
members.forEach(app -> {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(app.getAppId());
config.setSecret(app.getSecret());
config.setMsgDataFormat(JSON_STR);
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
maServicesNew.put(app.getAppId(), service);
});
}
} catch (Exception ex) {
logger.error("init wxMaService from redis error", ex);
}
try {
Result<List<CustomerAppDTO>> configAllAppResult = operCrmOpenFeignClient.getConfigAllApp();
logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp result:{}", JSON.toJSONString(configAllAppResult));
if (configAllAppResult == null || !configAllAppResult.success()){
logger.info("initWxMa operCrmOpenFeignClient.getConfigAllApp fail");
logger.info("wxMaService operCrmOpenFeignClient.getConfigAllApp result:{}", JSON.toJSONString(configAllAppResult));
if (configAllAppResult == null || !configAllAppResult.success()) {
logger.info("wxMaService operCrmOpenFeignClient.getConfigAllApp fail");
return;
}
String appKey = RedisKeys.getCustomerAppKey();
SetOperations<String, String> appSet = redisTemplate.opsForSet();
Set<String> members = appSet.members(appKey);
if ( !CollectionUtils.isEmpty(configAllAppResult.getData())) {
//if (!CollectionUtils.isEmpty(members) && CollectionUtils.isEmpty()){
//todo
//}
maServices = configAllAppResult.getData().stream()
.map(a -> {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(a.getAppId());
config.setSecret(a.getSecret());
config.setMsgDataFormat(JSON_STR);
result = configAllAppResult.getData();
result.forEach(app -> {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid(app.getAppId());
config.setSecret(app.getSecret());
config.setMsgDataFormat(JSON_STR);
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
redisTemplate.opsForSet().add(appKey,a.getSecret());
return service;
}).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
}
WxMaService service = new WxMaServiceImpl();
service.setWxMaConfig(config);
maServicesNew.put(app.getAppId(), service);
});
} catch (Exception e) {
logger.error("init wxMaservice exception",e);
} finally {
logger.info("init wxMaservice end");
logger.error("init wxMaService from db exception", e);
}
if (maServicesNew.size() > 0) {
maServices = maServicesNew;
if (appSet != null && result != null) {
appSet.add(appKey, result);
}
}
}
}

55
epmet-module/oper-crm/oper-crm-client/src/main/java/com/epmet/dto/CustomerAppRedisDTO.java

@ -0,0 +1,55 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dto;
import lombok.Data;
import java.io.Serializable;
/**
* 客户表 app redis 缓存对象
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-27
*/
@Data
public class CustomerAppRedisDTO implements Serializable {
private static final long serialVersionUID = -1619187268905620766L;
/**
* 客户Id
*/
private String customerId;
/**
* 小程序的appId
*/
private String appId;
/**
* resiwork
*/
private String client;
/**
* app的secret
*/
private String secret;
}

4
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/controller/CustomerAppController.java

@ -25,7 +25,7 @@ import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.CustomerAppDTO;
import com.epmet.dto.form.CustomerAppSecretFormDTO;
import com.epmet.service.CustomerAppIdService;
import com.epmet.service.CustomerAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -44,7 +44,7 @@ import java.util.Map;
public class CustomerAppController {
@Autowired
private CustomerAppIdService customerAppIdService;
private CustomerAppService customerAppIdService;
@GetMapping("page")
public Result<PageData<CustomerAppDTO>> page(@RequestParam Map<String, Object> params){

2
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppIdService.java → epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/CustomerAppService.java

@ -31,7 +31,7 @@ import java.util.Map;
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-27
*/
public interface CustomerAppIdService extends BaseService<CustomerAppEntity> {
public interface CustomerAppService extends BaseService<CustomerAppEntity> {
/**
* 默认分页

33
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppIdServiceImpl.java → epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerAppServiceImpl.java

@ -22,26 +22,53 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.dao.CustomerAppDao;
import com.epmet.dto.CustomerAppDTO;
import com.epmet.dto.CustomerAppRedisDTO;
import com.epmet.entity.CustomerAppEntity;
import com.epmet.service.CustomerAppIdService;
import com.epmet.service.CustomerAppService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
/**
* 客户表 appId
* 客户表 app表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-27
*/
@Slf4j
@Service
public class CustomerAppIdServiceImpl extends BaseServiceImpl<CustomerAppDao, CustomerAppEntity> implements CustomerAppIdService {
public class CustomerAppServiceImpl extends BaseServiceImpl<CustomerAppDao, CustomerAppEntity> implements CustomerAppService {
@Autowired
private RedisTemplate redisTemplate;
@PostConstruct
private void initApp2Redis() {
SetOperations<String, CustomerAppRedisDTO> appSet = redisTemplate.opsForSet();
List<CustomerAppDTO> configAllApp = this.getConfigAllApp();
if (!CollectionUtils.isEmpty(configAllApp)) {
String appKey = RedisKeys.getCustomerAppKey();
List<CustomerAppRedisDTO> redisDTOS = ConvertUtils.sourceToTarget(configAllApp, CustomerAppRedisDTO.class);
if (CollectionUtils.isEmpty(redisDTOS)) {
log.error("initApp2Redis fail,convert return null");
return;
}
redisDTOS.forEach(app -> appSet.add(appKey, app));
log.info("initApp2Redis success");
}
}
@Override
public PageData<CustomerAppDTO> page(Map<String, Object> params) {
Loading…
Cancel
Save