|
|
@ -9,30 +9,31 @@ 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.AuthorizationInfoDTO; |
|
|
|
import com.epmet.dto.CodeAuditResultDTO; |
|
|
|
import com.epmet.dto.CodeCustomerDTO; |
|
|
|
import com.epmet.dto.CustomerDTO; |
|
|
|
import com.epmet.dto.*; |
|
|
|
import com.epmet.dto.form.CodeCommonFormDTO; |
|
|
|
import com.epmet.dto.form.CodeUploadFormDTO; |
|
|
|
import com.epmet.dto.form.SubmitAuditFormDTO; |
|
|
|
import com.epmet.dto.form.UploadListFormDTO; |
|
|
|
import com.epmet.dto.result.TemplateListResultDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
|
import com.epmet.service.CodeAuditResultService; |
|
|
|
import com.epmet.service.CodeCustomerService; |
|
|
|
import com.epmet.service.CodeService; |
|
|
|
import com.epmet.service.*; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeCommitReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; |
|
|
|
import com.epmet.wxapi.param.WxMaNewsReq; |
|
|
|
import com.epmet.wxapi.result.WxMaAuditStatusResult; |
|
|
|
import com.epmet.wxapi.result.WxMaNewsResult; |
|
|
|
import com.epmet.wxapi.result.WxMaTemplateResult; |
|
|
|
import com.epmet.wxapi.result.WxResult; |
|
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -55,6 +56,10 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private CodeAuditResultService codeAuditResultService; |
|
|
|
@Autowired |
|
|
|
private CustomerMpService customerMpService; |
|
|
|
@Autowired |
|
|
|
private CodeOperationHistoryService codeOperationHistoryService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TemplateListResultDTO> templateList() { |
|
|
@ -81,7 +86,12 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void upload(CodeUploadFormDTO formDTO) { |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(formDTO.getCustomerId(), formDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
|
if (null == authInfo) { |
|
|
@ -96,6 +106,7 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
WxResult wxResult = wxMaCodeService.commit(authInfo.getAuthorizerAccessToken(), request); |
|
|
|
//上传失败,抛出异常
|
|
|
|
if (!wxResult.success()) { |
|
|
|
saveOperation(formDTO.getCustomerId(), null, formDTO.getUserVersion(), CodeConstant.OPER_UPLOAD, wxResult.getErrorMsg()); |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//获取客户信息
|
|
|
@ -105,7 +116,8 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
if (!customerInfo.success()) { |
|
|
|
throw new RenException(customerInfo.getCode(), customerInfo.getMsg()); |
|
|
|
} |
|
|
|
//TODO 将之前上传信息删除
|
|
|
|
//将之前上传信息删除
|
|
|
|
codeCustomerService.deleteCode(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
|
|
|
|
|
//将上传信息存入表中
|
|
|
|
CodeCustomerDTO codeCustomerDTO = ConvertUtils.sourceToTarget(formDTO, CodeCustomerDTO.class); |
|
|
@ -113,11 +125,42 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
codeCustomerDTO.setExtJson(extJson); |
|
|
|
codeCustomerDTO.setStatus(CodeConstant.UNAUDITED); |
|
|
|
codeCustomerService.save(codeCustomerDTO); |
|
|
|
|
|
|
|
saveOperation(formDTO.getCustomerId(), codeCustomerDTO.getId(), formDTO.getUserVersion(), CodeConstant.OPER_UPLOAD, "上传成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData uploadList(UploadListFormDTO formDTO) { |
|
|
|
//TODO 更新审核状态
|
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
|
List<CodeCustomerDTO> auditingList = codeCustomerService.getAuditingCodeList(); |
|
|
|
auditingList.forEach(code -> { |
|
|
|
//获取审核结果信息
|
|
|
|
CodeAuditResultDTO auditResult = codeAuditResultService.getAuditResultByCodeId(code.getId()); |
|
|
|
//调用微信API获取最新审核状态
|
|
|
|
WxMaCodeAuditStatusReq request = new WxMaCodeAuditStatusReq(); |
|
|
|
request.setAuditId(auditResult.getAuditId()); |
|
|
|
WxResult<WxMaAuditStatusResult> wxAuditResult = wxMaCodeService.getAuditStatus(authInfo.getAuthorizerAccessToken(), request); |
|
|
|
if (wxAuditResult.success()) { |
|
|
|
WxMaAuditStatusResult result = wxAuditResult.getData(); |
|
|
|
if(result.getStatus() == NumConstant.ZERO) { |
|
|
|
code.setStatus(CodeConstant.AUDIT_SUCCESS); |
|
|
|
auditResult.setResult(CodeConstant.AUDIT_SUCCESS); |
|
|
|
codeOperationHistoryService.updateDescribe(code.getId(), "审核成功"); |
|
|
|
} else if(result.getStatus() == NumConstant.ONE) { |
|
|
|
code.setStatus(CodeConstant.AUDIT_FAILED); |
|
|
|
auditResult.setResult(CodeConstant.AUDIT_FAILED); |
|
|
|
auditResult.setReason(result.getReason()); |
|
|
|
codeOperationHistoryService.updateDescribe(code.getId(), result.getReason()); |
|
|
|
} else if(result.getStatus() == NumConstant.FOUR) { |
|
|
|
code.setStatus(CodeConstant.DELAY); |
|
|
|
auditResult.setResult(CodeConstant.DELAY); |
|
|
|
codeOperationHistoryService.updateDescribe(code.getId(), "审核延后"); |
|
|
|
} |
|
|
|
codeCustomerService.update(code); |
|
|
|
codeAuditResultService.update(auditResult); |
|
|
|
} |
|
|
|
}); |
|
|
|
return codeCustomerService.getCodeList(formDTO); |
|
|
|
} |
|
|
|
|
|
|
@ -125,12 +168,18 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
public void submitAudit(SubmitAuditFormDTO formDTO) { |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//调用微信API上提交审核
|
|
|
|
WxMaCodeSubmitAuditRequest request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeSubmitAuditRequest.class); |
|
|
|
WxResult<String> wxResult = wxMaCodeService.submitAudit(authInfo.getAuthorizerAccessToken(), request); |
|
|
|
if (!wxResult.success()) { |
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_SUBMIT, |
|
|
|
wxResult.getErrorMsg()); |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//将数据存入代码审核表
|
|
|
@ -143,12 +192,18 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.AUDITING); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_SUBMIT, |
|
|
|
"审核中"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void undo(CodeCommonFormDTO formDTO) { |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//获取审核结果信息
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId()); |
|
|
|
//获取小程序调用令牌
|
|
|
@ -166,6 +221,8 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
//调用微信API撤销审核
|
|
|
|
WxResult wxResult = wxMaCodeService.undoCodeAudit(authInfo.getAuthorizerAccessToken()); |
|
|
|
if (!wxResult.success()) { |
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_UNDO, |
|
|
|
wxResult.getErrorMsg()); |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//更新审核结果
|
|
|
@ -174,6 +231,111 @@ public class CodeServiceImpl implements CodeService { |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.WITHDRAWN); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
//更新审核操作记录描述
|
|
|
|
codeOperationHistoryService.updateDescribe(codeCustomerDTO.getId(), "已撤回"); |
|
|
|
|
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_UNDO, |
|
|
|
"成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void release(CodeCommonFormDTO formDTO) { |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//调用微信API发布代码
|
|
|
|
WxResult wxResult = wxMaCodeService.release(authInfo.getAuthorizerAccessToken()); |
|
|
|
if (!wxResult.success()) { |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.RELEASE_FAILED); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_RELEASE, |
|
|
|
wxResult.getErrorMsg()); |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.RELEASE_SUCCESS); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_RELEASE, |
|
|
|
"发布成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ReasonResultDTO reason(CodeCommonFormDTO formDTO) { |
|
|
|
ReasonResultDTO result = new ReasonResultDTO(); |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//TODO 获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//获取审核结果信息
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId()); |
|
|
|
result.setReason(codeAuditResultDTO.getReason()); |
|
|
|
String[] mediaIds = codeAuditResultDTO.getScreenShot().split("[|]"); |
|
|
|
List<String> mediaIdList = new ArrayList<>(mediaIds.length); |
|
|
|
Collections.addAll(mediaIdList, mediaIds); |
|
|
|
List<String> urlList = new ArrayList<>(); |
|
|
|
mediaIdList.forEach(mediaId -> { |
|
|
|
//调用微信API获取素材
|
|
|
|
WxMaCodeAuditStatusReq request = new WxMaCodeAuditStatusReq(); |
|
|
|
request.setAuditId(codeAuditResultDTO.getAuditId()); |
|
|
|
WxMaNewsReq wxMaNewsReq = new WxMaNewsReq(); |
|
|
|
wxMaNewsReq.setMediaId(mediaId); |
|
|
|
WxResult<WxMaNewsResult> wxAuditResult = wxMaCodeService.getMaterial(authInfo.getAuthorizerAccessToken(), wxMaNewsReq); |
|
|
|
wxAuditResult.getData().getNewsItem().forEach(news -> { |
|
|
|
urlList.add(news.getUrl()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
result.setScreenshotUrl(urlList); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public QrCodeResultDTO qrCode(CodeCommonFormDTO formDTO) { |
|
|
|
QrCodeResultDTO result = new QrCodeResultDTO(); |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//是否授权
|
|
|
|
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//调用微信API获取获取体验版二维码
|
|
|
|
WxResult<Byte[]> wxResult = wxMaCodeService.getQrCode(authInfo.getAuthorizerAccessToken(), null); |
|
|
|
if (!wxResult.success()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
result.setQrcode(wxResult.getData()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData history(CodeCommonFormDTO formDTO) { |
|
|
|
PageHelper.startPage(formDTO.getPage(), formDTO.getLimit()); |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
List<CodeHistoryResultDTO> list = codeOperationHistoryService.getHistoryList(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
PageInfo<CodeHistoryResultDTO> pageInfo = new PageInfo<>(list); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
private void saveOperation(String customerId, String codeId, String version, String operation, String describe) { |
|
|
|
CodeOperationHistoryDTO operationDTO = new CodeOperationHistoryDTO(); |
|
|
|
operationDTO.setCustomerId(customerId); |
|
|
|
operationDTO.setCodeId(codeId); |
|
|
|
operationDTO.setVersion(version); |
|
|
|
operationDTO.setOperation(operation); |
|
|
|
operationDTO.setDescribe(describe); |
|
|
|
codeOperationHistoryService.save(operationDTO); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|