|
|
@ -25,6 +25,7 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
@ -48,6 +49,7 @@ import com.epmet.resi.group.dto.group.form.CreateGroupCodeFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.form.GetGroupCodeFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.form.GroupCodeBasicInfoFormDTO; |
|
|
|
import com.epmet.resi.group.dto.group.result.GroupCodeBasicInfoResultDTO; |
|
|
|
import com.epmet.utils.ThirdUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -58,6 +60,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 小组二维码 小组唯一二维码,海报码和小组码是同一个二维码,长期有效的 |
|
|
@ -76,6 +79,9 @@ public class ResiGroupCodeServiceImpl extends BaseServiceImpl<ResiGroupCodeDao, |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExecutorService executorService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ResiGroupCodeDTO> page(Map<String, Object> params) { |
|
|
|
IPage<ResiGroupCodeEntity> page = baseDao.selectPage( |
|
|
@ -129,14 +135,68 @@ public class ResiGroupCodeServiceImpl extends BaseServiceImpl<ResiGroupCodeDao, |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param dto |
|
|
|
* @return void |
|
|
|
* @param dto, syncFlag(是否同步执行,true同步,false异步) |
|
|
|
* @return String |
|
|
|
* @Description 创建群组二维码 |
|
|
|
* @Author liushaowen |
|
|
|
* @Date 2020/11/13 16:32 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String createGroupCode(CreateGroupCodeFormDTO dto) { |
|
|
|
public String createGroupCode(CreateGroupCodeFormDTO dto, boolean syncFlag) { |
|
|
|
if (syncFlag){ |
|
|
|
return createCodeFunction(dto); |
|
|
|
}else { |
|
|
|
executorService.execute(()->{ |
|
|
|
try { |
|
|
|
long startTs = System.currentTimeMillis(); |
|
|
|
createCodeFunction(dto); |
|
|
|
long endTs = System.currentTimeMillis(); |
|
|
|
logger.info("异步创建群二维码成功,执行时长:{}", endTs - startTs); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("异步创建群二维码失败,错误信息:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
} |
|
|
|
}); |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param dto |
|
|
|
* @return com.epmet.commons.tools.utils.Result<java.lang.String> |
|
|
|
* @Description 获取群组二维码 |
|
|
|
* @Author liushaowen |
|
|
|
* @Date 2020/11/16 9:37 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Result<String> getGroupCode(GetGroupCodeFormDTO dto) { |
|
|
|
ResiGroupCodeEntity codeByGroupId = getCode(dto.getGroupId(), dto.getType()); |
|
|
|
if (codeByGroupId != null) { |
|
|
|
//数据库有数据
|
|
|
|
return new Result<String>().ok(codeByGroupId.getUrl()); |
|
|
|
} else { |
|
|
|
//从微信获取二维码并存储
|
|
|
|
CreateGroupCodeFormDTO createDto = new CreateGroupCodeFormDTO(); |
|
|
|
BeanUtils.copyProperties(dto, createDto); |
|
|
|
String url = createGroupCode(createDto, false); |
|
|
|
if (StringUtils.isBlank(url)){ |
|
|
|
throw new RenException("获取二维码失败"); |
|
|
|
} |
|
|
|
return new Result<String>().ok(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private ResiGroupCodeEntity getCode(String groupId, String type) { |
|
|
|
if (StringUtils.isBlank(groupId) || StringUtils.isBlank(type)) { |
|
|
|
throw new RenException("获取二维码失败,groupId或type为空"); |
|
|
|
} |
|
|
|
QueryWrapper<ResiGroupCodeEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("DEL_FLAG", "0"); |
|
|
|
queryWrapper.eq("GROUP_ID", groupId); |
|
|
|
queryWrapper.eq("TYPE", type); |
|
|
|
return baseDao.selectOne(queryWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
private String createCodeFunction(CreateGroupCodeFormDTO dto){ |
|
|
|
String result = ""; |
|
|
|
ResiGroupCodeEntity codeByGroupId = getCode(dto.getGroupId(), dto.getType()); |
|
|
|
if (codeByGroupId != null) { |
|
|
@ -146,7 +206,7 @@ public class ResiGroupCodeServiceImpl extends BaseServiceImpl<ResiGroupCodeDao, |
|
|
|
//向微信获取二维码
|
|
|
|
|
|
|
|
// 获取AccessToken
|
|
|
|
String accessToken = getAccessToken(dto.getCustomerId()); |
|
|
|
String accessToken = ThirdUtils.getAccessToken(dto.getCustomerId()).getResiToken(); |
|
|
|
if (StringUtils.isBlank(accessToken)) { |
|
|
|
logger.error("获取accessToken失败,customerId:{}", dto.getCustomerId()); |
|
|
|
throw new RenException("获取accessToken失败"); |
|
|
@ -192,70 +252,6 @@ public class ResiGroupCodeServiceImpl extends BaseServiceImpl<ResiGroupCodeDao, |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param dto |
|
|
|
* @return com.epmet.commons.tools.utils.Result<java.lang.String> |
|
|
|
* @Description 获取群组二维码 |
|
|
|
* @Author liushaowen |
|
|
|
* @Date 2020/11/16 9:37 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Result<String> getGroupCode(GetGroupCodeFormDTO dto) { |
|
|
|
ResiGroupCodeEntity codeByGroupId = getCode(dto.getGroupId(), dto.getType()); |
|
|
|
if (codeByGroupId != null) { |
|
|
|
//数据库有数据
|
|
|
|
return new Result<String>().ok(codeByGroupId.getUrl()); |
|
|
|
} else { |
|
|
|
//从微信获取二维码并存储
|
|
|
|
CreateGroupCodeFormDTO createDto = new CreateGroupCodeFormDTO(); |
|
|
|
BeanUtils.copyProperties(dto, createDto); |
|
|
|
String url = createGroupCode(createDto); |
|
|
|
if (StringUtils.isBlank(url)){ |
|
|
|
throw new RenException("获取二维码失败"); |
|
|
|
} |
|
|
|
return new Result<String>().ok(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private ResiGroupCodeEntity getCode(String groupId, String type) { |
|
|
|
if (StringUtils.isBlank(groupId) || StringUtils.isBlank(type)) { |
|
|
|
throw new RenException("获取二维码失败,groupId或type为空"); |
|
|
|
} |
|
|
|
QueryWrapper<ResiGroupCodeEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("DEL_FLAG", "0"); |
|
|
|
queryWrapper.eq("GROUP_ID", groupId); |
|
|
|
queryWrapper.eq("TYPE", type); |
|
|
|
return baseDao.selectOne(queryWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
//获取AccessToken
|
|
|
|
private String getAccessToken(String customerId) { |
|
|
|
EnvEnum envEnum = EnvEnum.getCurrentEnv(); |
|
|
|
String resiAccessToken = null; |
|
|
|
if (EnvEnum.PROD.getCode().equals(envEnum.getCode())) { |
|
|
|
//居民端
|
|
|
|
StringBuilder resiKey = new StringBuilder(customerId).append(":resi"); |
|
|
|
Map<String, Object> authorizerRefreshToken = new HashMap<>(); |
|
|
|
authorizerRefreshToken = resiGroupCodeRedis.getAuthorizerRefreshToken(resiKey.toString()); |
|
|
|
resiAccessToken = (String) authorizerRefreshToken.get("authorizerAccessToken"); |
|
|
|
} else { |
|
|
|
String url = "https://epmet-cloud.elinkservice.cn/api/third/pacustomer/tokenlist"; |
|
|
|
JSONObject postData = new JSONObject(); |
|
|
|
postData.put("customerId", customerId); |
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(postData)).getData(); |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
|
mapToResult.setCode(((Integer) toResult.get("code")).intValue()); |
|
|
|
} |
|
|
|
Object CustomerTokensResultDTO = mapToResult.getData(); |
|
|
|
JSONObject json = JSON.parseObject(CustomerTokensResultDTO.toString()); |
|
|
|
CustomerTokensResultDTO customerTokensResultDTO = ConvertUtils.mapToEntity(json, com.epmet.dto.result.CustomerTokensResultDTO.class); |
|
|
|
resiAccessToken = customerTokensResultDTO.getResiAuthorizerToken(); |
|
|
|
} |
|
|
|
return resiAccessToken; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @Description 获取生成海报(小组码)信息 |
|
|
@ -272,7 +268,7 @@ public class ResiGroupCodeServiceImpl extends BaseServiceImpl<ResiGroupCodeDao, |
|
|
|
if (null == resultDTO.getGroupCodeUrl() || "".equals(resultDTO.getGroupCodeUrl())) { |
|
|
|
CreateGroupCodeFormDTO dto = ConvertUtils.sourceToTarget(formDTO, CreateGroupCodeFormDTO.class); |
|
|
|
dto.setType(GroupCodeConstant.CODE_TYPE_INVITE); |
|
|
|
String url = createGroupCode(dto); |
|
|
|
String url = createGroupCode(dto, true); |
|
|
|
if (StringUtils.isBlank(url)) { |
|
|
|
logger.error(String.format("生成小组二维码失败,小组Id:%s", formDTO.getGroupId())); |
|
|
|
throw new RenException("获取小组码基本信息失败"); |
|
|
|