Browse Source

生成哨卡小程序码相关

dev
yujintao 6 years ago
parent
commit
391c685474
  1. 3
      esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/CustomServiceImpl.java
  2. 67
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/epidemic/service/impl/EpidemicSentryPostServiceImpl.java

3
esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/CustomServiceImpl.java

@ -18,6 +18,7 @@ import com.elink.esua.epdc.feign.AdminFeignClient;
import com.elink.esua.epdc.feign.CustomFeignClient; import com.elink.esua.epdc.feign.CustomFeignClient;
import com.elink.esua.epdc.redis.AppUserRedis; import com.elink.esua.epdc.redis.AppUserRedis;
import com.elink.esua.epdc.service.CustomService; import com.elink.esua.epdc.service.CustomService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -27,6 +28,7 @@ import org.springframework.stereotype.Service;
* @Author yinzuomei * @Author yinzuomei
* @Date 2020/1/28 11:42 * @Date 2020/1/28 11:42
*/ */
@Slf4j
@Service @Service
public class CustomServiceImpl implements CustomService { public class CustomServiceImpl implements CustomService {
@ -83,6 +85,7 @@ public class CustomServiceImpl implements CustomService {
private EpidemicSentryPostDTO getEpidemicSentryPostInfoByCode(String postCode) { private EpidemicSentryPostDTO getEpidemicSentryPostInfoByCode(String postCode) {
Result<EpidemicSentryPostDTO> epidemicSentryResult = customFeignClient.getEpidemicSentryBySentryPostCode(postCode); Result<EpidemicSentryPostDTO> epidemicSentryResult = customFeignClient.getEpidemicSentryBySentryPostCode(postCode);
if (!epidemicSentryResult.success() || null == epidemicSentryResult.getData()) { if (!epidemicSentryResult.success() || null == epidemicSentryResult.getData()) {
log.error("查询哨卡信息失败,哨卡编码{}", postCode);
throw new RenException("查询哨卡信息失败"); throw new RenException("查询哨卡信息失败");
} }
return epidemicSentryResult.getData(); return epidemicSentryResult.getData();

67
esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/epidemic/service/impl/EpidemicSentryPostServiceImpl.java

@ -211,8 +211,7 @@ public class EpidemicSentryPostServiceImpl extends BaseServiceImpl<EpidemicSentr
if (StringUtils.isNotBlank(entity.getMaCodeUrl())) { if (StringUtils.isNotBlank(entity.getMaCodeUrl())) {
throw new RenException("该小程序码已经存在!"); throw new RenException("该小程序码已经存在!");
} }
String param = String.valueOf(entity.getGridId()).concat("-").concat(entity.getSentryPostCode()); entity.setMaCodeUrl(this.createAndSaveMaCode(String.valueOf(entity.getGridId()), entity.getSentryPostCode()));
entity.setMaCodeUrl(this.createMaCode(param, MA_FRONT_PAGE_URL));
baseDao.updateById(entity); baseDao.updateById(entity);
return new Result().ok("生成单个小程序码成功。"); return new Result().ok("生成单个小程序码成功。");
} }
@ -235,8 +234,7 @@ public class EpidemicSentryPostServiceImpl extends BaseServiceImpl<EpidemicSentr
if (StringUtils.isNotBlank(entity.getMaCodeUrl())) { if (StringUtils.isNotBlank(entity.getMaCodeUrl())) {
continue; continue;
} }
String param = String.valueOf(entity.getGridId()).concat("-").concat(entity.getSentryPostCode()); entity.setMaCodeUrl(this.createAndSaveMaCode(String.valueOf(entity.getGridId()), entity.getSentryPostCode()));
entity.setMaCodeUrl(this.createMaCode(param, MA_FRONT_PAGE_URL));
baseDao.updateById(entity); baseDao.updateById(entity);
isHave = true; isHave = true;
} }
@ -247,23 +245,47 @@ public class EpidemicSentryPostServiceImpl extends BaseServiceImpl<EpidemicSentr
} }
/** /**
* 创建微信小程序码并上传到oss * 拼接生成小程序码字符串
* *
* @param param 小程序码的参数 * @param gridId 网格id
* @param pageUrl 小程序码的跳转链接 * @param postCode 哨卡编码
* @return java.lang.String 小程序码的下载抵制 * @return java.lang.String
* @author work@yujt.net.cn * @author work@yujt.net.cn
* @date 2019/10/22 10:14 * @date 2020/2/17 16:49
*/ */
private String createMaCode(String param, String pageUrl) { private String concatStrForMaCode(String gridId, String postCode) {
return gridId.concat("-").concat(postCode);
}
/**
* 拼接url的方式生成小程序码
*
* @param gridId 网格id
* @param postCode 哨卡编码
* @return java.lang.String
* @author work@yujt.net.cn
* @date 2020/2/17 19:16
*/
private String createAndSaveMaCode(String gridId, String postCode) {
String url = MA_FRONT_PAGE_URL.concat("?G=").concat(gridId).concat("&P=").concat(postCode);
File wxaCodeUnlimit; File wxaCodeUnlimit;
try { try {
wxaCodeUnlimit = wxMaServiceUtils.normalWxMaService().getQrcodeService() wxaCodeUnlimit = wxMaServiceUtils.normalWxMaService().getQrcodeService().createWxaCode(url, 1280);
.createWxaCodeUnlimit(param, pageUrl, 1280, true, null, false);
} catch (WxErrorException e) { } catch (WxErrorException e) {
throw new RenException("请求微信接口失败"); throw new RenException("请求微信接口失败");
} }
return uploadFile(wxaCodeUnlimit);
}
/**
* 将小程序码上传到oss返回访问url
*
* @param wxaCodeUnlimit 图片文件
* @return java.lang.String
* @author work@yujt.net.cn
* @date 2020/2/17 19:16
*/
private String uploadFile(File wxaCodeUnlimit) {
UploadToOssDTO dto = new UploadToOssDTO(); UploadToOssDTO dto = new UploadToOssDTO();
dto.setFileByte(this.fileToByteArray(wxaCodeUnlimit)); dto.setFileByte(this.fileToByteArray(wxaCodeUnlimit));
dto.setFileName(wxaCodeUnlimit.getName()); dto.setFileName(wxaCodeUnlimit.getName());
@ -275,6 +297,27 @@ public class EpidemicSentryPostServiceImpl extends BaseServiceImpl<EpidemicSentr
return ossResult.getData(); return ossResult.getData();
} }
/**
* 创建微信小程序码并上传到oss
*
* @param param 小程序码的参数
* @param pageUrl 小程序码的跳转链接
* @return java.lang.String 小程序码的下载抵制
* @author work@yujt.net.cn
* @date 2019/10/22 10:14
*/
private String createMaCode(String param, String pageUrl) {
File wxaCodeUnlimit;
try {
wxaCodeUnlimit = wxMaServiceUtils.normalWxMaService().getQrcodeService()
.createWxaCodeUnlimit(param, pageUrl, 1280, true, null, false);
} catch (WxErrorException e) {
throw new RenException("请求微信接口失败");
}
return uploadFile(wxaCodeUnlimit);
}
/** /**
* File文件转为byte[] * File文件转为byte[]
* *

Loading…
Cancel
Save