|
|
@ -1,9 +1,38 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
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.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.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.feign.OperCrmOpenFeignClient; |
|
|
|
import com.epmet.service.CodeAuditResultService; |
|
|
|
import com.epmet.service.CodeCustomerService; |
|
|
|
import com.epmet.service.CodeService; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeCommitReq; |
|
|
|
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; |
|
|
|
import com.epmet.wxapi.result.WxMaAuditStatusResult; |
|
|
|
import com.epmet.wxapi.result.WxMaTemplateResult; |
|
|
|
import com.epmet.wxapi.result.WxResult; |
|
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -14,4 +43,137 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
public class CodeServiceImpl implements CodeService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMaCodeService wxMaCodeService; |
|
|
|
@Autowired |
|
|
|
private ComponentAccessTokenDao componentAccessTokenDao; |
|
|
|
@Autowired |
|
|
|
private AuthorizationInfoDao authorizationInfoDao; |
|
|
|
@Autowired |
|
|
|
private CodeCustomerService codeCustomerService; |
|
|
|
@Autowired |
|
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private CodeAuditResultService codeAuditResultService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TemplateListResultDTO> templateList() { |
|
|
|
List<TemplateListResultDTO> resultList = new ArrayList<>(); |
|
|
|
//获取COMPONENT_ACCESS_TOKEN
|
|
|
|
String accessToken = componentAccessTokenDao.getComponentAccessToken(); |
|
|
|
//调用微信API获取模板列表
|
|
|
|
WxResult<List<WxMaTemplateResult>> wxResult = wxMaCodeService.getTemplateList(accessToken); |
|
|
|
if (!wxResult.success()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
if (null == wxResult.getData() || wxResult.getData().size() == NumConstant.ZERO) { |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
wxResult.getData().forEach(temp -> { |
|
|
|
TemplateListResultDTO dto = new TemplateListResultDTO(); |
|
|
|
dto.setTemplateId(temp.getTemplateId()); |
|
|
|
dto.setUserVersion(temp.getUserVersion()); |
|
|
|
dto.setUserDesc(temp.getUserDesc()); |
|
|
|
dto.setCreateTime(DateUtils.formatTimestamp(temp.getCreateTime(), DateUtils.DATE_PATTERN)); |
|
|
|
resultList.add(dto); |
|
|
|
}); |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void upload(CodeUploadFormDTO formDTO) { |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
|
if (null == authInfo) { |
|
|
|
throw new RenException("未授权"); |
|
|
|
} |
|
|
|
//TODO 获取第三方自定义配置
|
|
|
|
String extJson = "{}"; |
|
|
|
|
|
|
|
WxMaCodeCommitReq request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeCommitReq.class); |
|
|
|
request.setExtJson(extJson); |
|
|
|
//调用微信API上传代码
|
|
|
|
WxResult wxResult = wxMaCodeService.commit(authInfo.getAuthorizerAccessToken(), request); |
|
|
|
//上传失败,抛出异常
|
|
|
|
if (!wxResult.success()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//获取客户信息
|
|
|
|
CustomerDTO customerDTO = new CustomerDTO(); |
|
|
|
customerDTO.setId(formDTO.getCustomerId()); |
|
|
|
Result<CustomerDTO> customerInfo = operCrmOpenFeignClient.getCustomerInfo(customerDTO); |
|
|
|
if (!customerInfo.success()) { |
|
|
|
throw new RenException(customerInfo.getCode(), customerInfo.getMsg()); |
|
|
|
} |
|
|
|
//TODO 将之前上传信息删除
|
|
|
|
|
|
|
|
//将上传信息存入表中
|
|
|
|
CodeCustomerDTO codeCustomerDTO = ConvertUtils.sourceToTarget(formDTO, CodeCustomerDTO.class); |
|
|
|
codeCustomerDTO.setCustomerName(customerInfo.getData().getCustomerName()); |
|
|
|
codeCustomerDTO.setExtJson(extJson); |
|
|
|
codeCustomerDTO.setStatus(CodeConstant.UNAUDITED); |
|
|
|
codeCustomerService.save(codeCustomerDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData uploadList(UploadListFormDTO formDTO) { |
|
|
|
//TODO 更新审核状态
|
|
|
|
return codeCustomerService.getCodeList(formDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void submitAudit(SubmitAuditFormDTO formDTO) { |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//获取小程序调用令牌
|
|
|
|
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()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//将数据存入代码审核表
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = new CodeAuditResultDTO(); |
|
|
|
codeAuditResultDTO.setCustomerId(codeCustomerDTO.getCustomerId()); |
|
|
|
codeAuditResultDTO.setCodeId(codeCustomerDTO.getId()); |
|
|
|
codeAuditResultDTO.setAuditId(wxResult.getData()); |
|
|
|
codeAuditResultDTO.setResult(CodeConstant.AUDITING); |
|
|
|
codeAuditResultService.save(codeAuditResultDTO); |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.AUDITING); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void undo(CodeCommonFormDTO formDTO) { |
|
|
|
//获取上传代码信息
|
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
|
//获取审核结果信息
|
|
|
|
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId()); |
|
|
|
//获取小程序调用令牌
|
|
|
|
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); |
|
|
|
//调用微信API获取最新审核状态
|
|
|
|
WxMaCodeAuditStatusReq request = new WxMaCodeAuditStatusReq(); |
|
|
|
request.setAuditId(codeAuditResultDTO.getAuditId()); |
|
|
|
WxResult<WxMaAuditStatusResult> wxAuditResult = wxMaCodeService.getAuditStatus(authInfo.getAuthorizerAccessToken(), request); |
|
|
|
if (!wxAuditResult.success() ) { |
|
|
|
throw new RenException(wxAuditResult.getErrorCode(), wxAuditResult.getErrorMsg()); |
|
|
|
} |
|
|
|
if (wxAuditResult.getData().getStatus() != NumConstant.TWO) { |
|
|
|
throw new RenException("该条记录状态已不是审核中,无法撤回"); |
|
|
|
} |
|
|
|
//调用微信API撤销审核
|
|
|
|
WxResult wxResult = wxMaCodeService.undoCodeAudit(authInfo.getAuthorizerAccessToken()); |
|
|
|
if (!wxResult.success()) { |
|
|
|
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg()); |
|
|
|
} |
|
|
|
//更新审核结果
|
|
|
|
codeAuditResultDTO.setResult(CodeConstant.WITHDRAWN); |
|
|
|
codeAuditResultService.update(codeAuditResultDTO); |
|
|
|
//更新代码表状态
|
|
|
|
codeCustomerDTO.setStatus(CodeConstant.WITHDRAWN); |
|
|
|
codeCustomerService.update(codeCustomerDTO); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|