|
@ -14,7 +14,6 @@ import com.epmet.dao.ComponentAccessTokenDao; |
|
|
import com.epmet.dto.*; |
|
|
import com.epmet.dto.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.service.*; |
|
|
import com.epmet.service.*; |
|
|
import com.epmet.wxapi.param.*; |
|
|
import com.epmet.wxapi.param.*; |
|
@ -22,6 +21,8 @@ import com.epmet.wxapi.result.*; |
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
import com.epmet.wxapi.service.WxMaCodeService; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
@ -29,17 +30,18 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Comparator; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author zhaoqifeng |
|
|
* @author zhaoqifeng |
|
|
* @dscription |
|
|
* @dscription |
|
|
* @date 2020/7/10 10:27 |
|
|
* @date 2020/7/10 10:27 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class CodeServiceImpl implements CodeService { |
|
|
public class CodeServiceImpl implements CodeService { |
|
|
|
|
|
|
|
@ -52,8 +54,6 @@ public class CodeServiceImpl implements CodeService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CodeCustomerService codeCustomerService; |
|
|
private CodeCustomerService codeCustomerService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CodeAuditResultService codeAuditResultService; |
|
|
private CodeAuditResultService codeAuditResultService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerMpService customerMpService; |
|
|
private CustomerMpService customerMpService; |
|
@ -81,12 +81,14 @@ public class CodeServiceImpl implements CodeService { |
|
|
if (null == wxResult.getData() || wxResult.getData().size() == NumConstant.ZERO) { |
|
|
if (null == wxResult.getData() || wxResult.getData().size() == NumConstant.ZERO) { |
|
|
return resultList; |
|
|
return resultList; |
|
|
} |
|
|
} |
|
|
wxResult.getData().forEach(temp -> { |
|
|
List<WxMaTemplateResult> sortList = |
|
|
|
|
|
wxResult.getData().stream().sorted(Comparator.comparing(WxMaTemplateResult::getCreateTime).reversed()).collect(Collectors.toList()); |
|
|
|
|
|
sortList.forEach(temp -> { |
|
|
TemplateListResultDTO dto = new TemplateListResultDTO(); |
|
|
TemplateListResultDTO dto = new TemplateListResultDTO(); |
|
|
dto.setId(temp.getTemplateId()); |
|
|
dto.setId(temp.getTemplateId()); |
|
|
dto.setUserVersion(temp.getUserVersion()); |
|
|
dto.setUserVersion(temp.getUserVersion()); |
|
|
dto.setUserDesc(temp.getUserDesc()); |
|
|
dto.setUserDesc(temp.getUserDesc()); |
|
|
dto.setCreateTime(DateUtils.formatTimestamp(temp.getCreateTime(), DateUtils.DATE_PATTERN)); |
|
|
dto.setCreateTime(DateUtils.formatTimestamp(temp.getCreateTime(), DateUtils.DATE_TIME_PATTERN)); |
|
|
resultList.add(dto); |
|
|
resultList.add(dto); |
|
|
}); |
|
|
}); |
|
|
return resultList; |
|
|
return resultList; |
|
@ -101,14 +103,6 @@ public class CodeServiceImpl implements CodeService { |
|
|
return codeExtDTO.getExtJson(); |
|
|
return codeExtDTO.getExtJson(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
String json = "{\"extEnable\":true,\"extAppid\":\"wx2679392c4cc2af22\",\"directCommit\":false,\"ext\":{\"extAppid\":\"wx2679392c4cc2af22\",\"footbar\":{\"work\":{\"name\":\"工作\",\"pageTile\":\"工作\"},\"org\":{\"name\":\"组织\",\"pageTile\":\"组织\"},\"data\":{\"name\":\"数据\",\"pageTile\":\"数据\"},\"find\":{\"name\":\"更多\",\"pageTile\":\"更多\"}}}}"; |
|
|
|
|
|
WxExtJson wxExtJson = JSONObject.parseObject(json, WxExtJson.class); |
|
|
|
|
|
wxExtJson.setExtAppid("123456"); |
|
|
|
|
|
wxExtJson.getExt().setExtAppid("123456"); |
|
|
|
|
|
String extJson = JSON.toJSONString(wxExtJson); |
|
|
|
|
|
System.out.println(extJson); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
@ -122,14 +116,11 @@ public class CodeServiceImpl implements CodeService { |
|
|
if (null == authInfo) { |
|
|
if (null == authInfo) { |
|
|
throw new RenException("未授权"); |
|
|
throw new RenException("未授权"); |
|
|
} |
|
|
} |
|
|
if (!isJson(formDTO.getExtJson())) { |
|
|
String extJson = getExtJson(formDTO); |
|
|
throw new RenException("第三方配置不是有效的Json"); |
|
|
WxExtJson wxExtJson = JSONObject.parseObject(extJson, WxExtJson.class); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxExtJson wxExtJson = JSONObject.parseObject(formDTO.getExtJson(), WxExtJson.class); |
|
|
|
|
|
wxExtJson.setExtAppid(authInfo.getAuthorizerAppid()); |
|
|
wxExtJson.setExtAppid(authInfo.getAuthorizerAppid()); |
|
|
wxExtJson.getExt().setExtAppid(authInfo.getAuthorizerAppid()); |
|
|
wxExtJson.getExt().setExtAppid(authInfo.getAuthorizerAppid()); |
|
|
String extJson = JSON.toJSONString(wxExtJson); |
|
|
extJson = JSON.toJSONString(wxExtJson); |
|
|
CodeExtDTO codeExtDTO = codeExtService.getExtByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
CodeExtDTO codeExtDTO = codeExtService.getExtByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); |
|
|
if (null == codeExtDTO) { |
|
|
if (null == codeExtDTO) { |
|
|
codeExtDTO = new CodeExtDTO(); |
|
|
codeExtDTO = new CodeExtDTO(); |
|
@ -373,7 +364,7 @@ public class CodeServiceImpl implements CodeService { |
|
|
//获取上传代码信息
|
|
|
//获取上传代码信息
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
if (null != codeCustomerDTO.getQrCode()) { |
|
|
if (null != codeCustomerDTO.getQrCode()) { |
|
|
result.setQrcode(codeCustomerDTO.getQrCode()); |
|
|
result.setQrcode(codeCustomerDTO.getQrCode()); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
//是否授权
|
|
|
//是否授权
|
|
@ -409,8 +400,8 @@ public class CodeServiceImpl implements CodeService { |
|
|
@Override |
|
|
@Override |
|
|
public String mediaUpload(MediaUploadFormDTO formDTO) { |
|
|
public String mediaUpload(MediaUploadFormDTO formDTO) { |
|
|
try { |
|
|
try { |
|
|
Result<UploadImgResultDTO> uploadWxImg = ossFeignClient.uploadWxImg(formDTO.getMedia()); |
|
|
File file = new File(formDTO.getMedia().getOriginalFilename()); |
|
|
File file = new File(uploadWxImg.getData().getUrl()); |
|
|
FileUtils.copyInputStreamToFile(formDTO.getMedia().getInputStream(), file); |
|
|
//获取上传代码信息
|
|
|
//获取上传代码信息
|
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); |
|
|
//获取小程序调用令牌
|
|
|
//获取小程序调用令牌
|
|
@ -443,50 +434,4 @@ public class CodeServiceImpl implements CodeService { |
|
|
codeOperationHistoryService.save(operationDTO); |
|
|
codeOperationHistoryService.save(operationDTO); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 校验是否是Json |
|
|
|
|
|
* |
|
|
|
|
|
* @param content |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
* @author zhaoqifeng |
|
|
|
|
|
* @date 2020/7/17 15:43 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean isJson(String content) { |
|
|
|
|
|
try { |
|
|
|
|
|
JSONObject jsonStr = JSONObject.parseObject(content); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|