|
|
@ -6,17 +6,13 @@ import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.MultipartFileToFileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.CodeConstant; |
|
|
|
import com.epmet.dao.AuthorizationInfoDao; |
|
|
|
import com.epmet.dao.ComponentAccessTokenDao; |
|
|
|
import com.epmet.dto.*; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.CodeHistoryResultDTO; |
|
|
|
import com.epmet.dto.result.QrCodeResultDTO; |
|
|
|
import com.epmet.dto.result.ReasonResultDTO; |
|
|
|
import com.epmet.dto.result.TemplateListResultDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.service.*; |
|
|
@ -33,6 +29,9 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
@ -67,6 +66,10 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
private CodeExtService codeExtService; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
@Autowired |
|
|
|
private PaCustomerService paCustomerService; |
|
|
|
@Autowired |
|
|
|
private WxMaCodeService wxsMaCodeService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TemplateListResultDTO> templateList() { |
|
|
@ -141,16 +144,13 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
//获取客户信息
|
|
|
|
CustomerDTO customerDTO = new CustomerDTO(); |
|
|
|
customerDTO.setId(formDTO.getCustomerId()); |
|
|
|
Result<CustomerDTO> customerInfo = operCrmOpenFeignClient.getCustomerInfo(customerDTO); |
|
|
|
if (!customerInfo.success()) { |
|
|
|
throw new RenException(customerInfo.getCode(), customerInfo.getMsg()); |
|
|
|
} |
|
|
|
PaCustomerDTO paCustomerDTO = paCustomerService.get(formDTO.getCustomerId()); |
|
|
|
//将之前上传信息删除
|
|
|
|
codeCustomerService.deleteCode(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
|
|
|
|
|
//将上传信息存入表中
|
|
|
|
CodeCustomerDTO codeCustomerDTO = ConvertUtils.sourceToTarget(formDTO, CodeCustomerDTO.class); |
|
|
|
codeCustomerDTO.setCustomerName(customerInfo.getData().getCustomerName()); |
|
|
|
codeCustomerDTO.setCustomerName(paCustomerDTO.getCustomerName()); |
|
|
|
codeCustomerDTO.setExtJson(formDTO.getExtJson()); |
|
|
|
codeCustomerDTO.setAppId(authInfo.getAuthorizerAppid()); |
|
|
|
codeCustomerDTO.setStatus(CodeConstant.UNAUDITED); |
|
|
@ -211,6 +211,7 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
if (null == authInfo) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
|
|
|
|
//调用微信API上提交审核
|
|
|
|
WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest(); |
|
|
|
request.setVersionDesc(formDTO.getVersionDesc()); |
|
|
@ -225,13 +226,20 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
wxResult.getErrorMsg()); |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//获取审核结果信息
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId()); |
|
|
|
if (null == codeAuditResultDTO) { |
|
|
|
//将数据存入代码审核表
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = new CodeAuditResultDTO(); |
|
|
|
codeAuditResultDTO = new CodeAuditResultDTO(); |
|
|
|
codeAuditResultDTO.setCustomerId(codeCustomerDTO.getCustomerId()); |
|
|
|
codeAuditResultDTO.setCodeId(codeCustomerDTO.getId()); |
|
|
|
codeAuditResultDTO.setAuditId(wxResult.getData()); |
|
|
|
codeAuditResultDTO.setResult(CodeConstant.AUDITING); |
|
|
|
codeAuditResultService.save(codeAuditResultDTO); |
|
|
|
} else { |
|
|
|
codeAuditResultDTO.setResult(CodeConstant.AUDITING); |
|
|
|
codeAuditResultService.update(codeAuditResultDTO); |
|
|
|
} |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.AUDITING); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
@ -354,6 +362,10 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
QrCodeResultDTO result = new QrCodeResultDTO(); |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
if (null != codeCustomerDTO.getQrCode()) { |
|
|
|
result.setQrcode(codeCustomerDTO.getQrCode()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
//是否授权
|
|
|
|
if (!customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
@ -361,11 +373,20 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//调用微信API获取获取体验版二维码
|
|
|
|
WxResult<Byte[]> wxResult = wxMaCodeService.getQrCode(authInfo.getAuthorizerAccessToken(), null); |
|
|
|
WxResult<File> wxResult = wxMaCodeService.getQrCode(authInfo.getAuthorizerAccessToken(), formDTO.getPath()); |
|
|
|
QrCodeDTO qrCodeDTO = new QrCodeDTO(); |
|
|
|
try { |
|
|
|
qrCodeDTO.setQrCode(Files.readAllBytes(wxResult.getData().toPath())); |
|
|
|
Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCode(qrCodeDTO); |
|
|
|
codeCustomerDTO.setQrCode(uploadResult.getData().getUrl()); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
result.setQrcode(uploadResult.getData().getUrl()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RenException(e.getMessage()); |
|
|
|
} |
|
|
|
if (!wxResult.success()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
result.setQrcode(wxResult.getData()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
@ -382,8 +403,10 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
@Override |
|
|
|
public String mediaUpload(MediaUploadFormDTO formDTO) { |
|
|
|
try { |
|
|
|
// Result<UploadDTO> uploadDTOResult = ossFeignClient.upload(formDTO.getMedia());
|
|
|
|
File file = MultipartFileToFileUtils.multipartFileToFile(formDTO.getMedia()); |
|
|
|
QrCodeDTO dto = new QrCodeDTO(); |
|
|
|
dto.setMedia(formDTO.getMedia()); |
|
|
|
Result<UploadImgResultDTO> uploadDTOResult = ossFeignClient.uploadWxImg(dto); |
|
|
|
File file = new File(uploadDTOResult.getData().getUrl()); |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//获取小程序调用令牌
|
|
|
@ -433,5 +456,33 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private byte[] toPrimitives(Byte[] oBytes) { |
|
|
|
byte[] bytes = new byte[oBytes.length]; |
|
|
|
|
|
|
|
for (int i = 0; i < oBytes.length; i++) { |
|
|
|
bytes[i] = oBytes[i]; |
|
|
|
} |
|
|
|
return bytes; |
|
|
|
} |
|
|
|
|
|
|
|
private void byteToFile(byte[] bytes) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
// 根据绝对路径初始化文件
|
|
|
|
File localFile = new File("."); |
|
|
|
if (!localFile.exists()) |
|
|
|
{ |
|
|
|
localFile.createNewFile(); |
|
|
|
} |
|
|
|
// 输出流
|
|
|
|
OutputStream os = new FileOutputStream(localFile); |
|
|
|
os.write(bytes); |
|
|
|
os.close(); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|