|
|
|
@ -2,7 +2,6 @@ package com.zdxt.knowledge.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.io.IoUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
@ -28,22 +27,18 @@ import com.zdxt.knowledge.domain.SceneManage; |
|
|
|
import com.zdxt.knowledge.mapper.SceneManageMapper; |
|
|
|
import com.zdxt.knowledge.service.ISceneManageService; |
|
|
|
import com.zdxt.knowledge.utils.ExcelUtil; |
|
|
|
import com.zdxt.knowledge.utils.QRCodeGeneratorUtil; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.FileCopyUtils; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.activation.MimetypesFileTypeMap; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.io.File; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
@ -90,7 +85,6 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查询列表 |
|
|
|
* |
|
|
|
@ -101,6 +95,7 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
public List<SceneManage> selectSceneManageListAll(SceneManage sceneManage) { |
|
|
|
return sceneManageMapper.selectSceneManageListAll(sceneManage); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询【请填写功能名称】列表 |
|
|
|
* |
|
|
|
@ -119,13 +114,15 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
public ZDResponse generateQRCode(SceneManage sceneManage) throws Exception { |
|
|
|
|
|
|
|
String accessToken = getAccessToken(); |
|
|
|
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken; |
|
|
|
String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; |
|
|
|
|
|
|
|
// 发送请求参数
|
|
|
|
JSONObject paramJson = new JSONObject(); |
|
|
|
paramJson.set("page", "subpkg/role/role"); |
|
|
|
paramJson.set("check_path", false); |
|
|
|
paramJson.set("path", "subpkg/role/role"); |
|
|
|
//paramJson.set("check_path", false);
|
|
|
|
paramJson.set("width", 280); |
|
|
|
//paramJson.set("auto_color", false);
|
|
|
|
//paramJson.set("is_hyaline", false);
|
|
|
|
//scene数据不能中文
|
|
|
|
paramJson.set("scene", sceneManage.getGuid()); |
|
|
|
//设置小程序码版本
|
|
|
|
@ -136,7 +133,7 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
InputStream inputStream = HttpUtils.postInputStream(url, paramJson); |
|
|
|
//存入本地数据库
|
|
|
|
File file = File.createTempFile("temp", ".png"); |
|
|
|
FileUtils.copyInputStreamToFile(inputStream,file); |
|
|
|
FileUtils.copyInputStreamToFile(inputStream, file); |
|
|
|
MultipartFile multipartFile = new LocalFileMultipartFile(file); |
|
|
|
String uploadPath = fileUploadApi.upload(multipartFile); |
|
|
|
zdxtFileCommonApi.deleteZdxtFileByIds(sceneManage.getGuid() + "0000"); |
|
|
|
@ -145,12 +142,39 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
sceneManage.setUrl(uploadPath); |
|
|
|
int result = sceneManageMapper.updateSceneManage(sceneManage); |
|
|
|
file.deleteOnExit(); |
|
|
|
if (result>0) { |
|
|
|
if (result > 0) { |
|
|
|
return ZDResponse.success("生成二维码成功"); |
|
|
|
} |
|
|
|
return ZDResponse.error("生成二维码失败"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ZDResponse createQrCode(SceneManage sceneManage) { |
|
|
|
try { |
|
|
|
if (Objects.nonNull(sceneManage.getGuid())) { |
|
|
|
//这个地方则是调用了工具类第二个方法
|
|
|
|
byte[] qrcode = QRCodeGeneratorUtil.getQRCodeImage(sceneManage.getGuid(), 350, 350); |
|
|
|
//存入本地数据库
|
|
|
|
File file = File.createTempFile("temp", ".png"); |
|
|
|
FileUtils.writeByteArrayToFile(file, qrcode); |
|
|
|
|
|
|
|
MultipartFile multipartFile = new LocalFileMultipartFile(file); |
|
|
|
String uploadPath = fileUploadApi.upload(multipartFile); |
|
|
|
zdxtFileCommonApi.deleteZdxtFileByIds(sceneManage.getGuid() + "0000"); |
|
|
|
zdxtFileCommonApi.insertZdxtFile(multipartFile, sceneManage.getGuid() + "0000", uploadPath); |
|
|
|
sceneManage.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
sceneManage.setUrl(uploadPath); |
|
|
|
sceneManageMapper.updateSceneManage(sceneManage); |
|
|
|
file.deleteOnExit(); |
|
|
|
} else { |
|
|
|
return ZDResponse.error("二维码参数不能为空"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return ZDResponse.success("生成二维码成功"); |
|
|
|
} |
|
|
|
|
|
|
|
public String getAccessToken() { |
|
|
|
String appid = APPID; |
|
|
|
String secret = SECRET; |
|
|
|
@ -232,7 +256,7 @@ public class SceneManageServiceImpl implements ISceneManageService { |
|
|
|
public ZDResponse deleteSceneManageByIds(String guids) { |
|
|
|
List<SceneManage> sceneManageList = sceneManageMapper.selectSceneManageByIds(Convert.toStrArray(guids)); |
|
|
|
if (CollectionUtils.isNotEmpty(sceneManageList)) { |
|
|
|
//由于工作流还没实现,暂时注释此段代码
|
|
|
|
//由于工作流还没实现,暂时注释此段代码
|
|
|
|
// long count = sceneManageList.stream().filter(item -> !Objects.equals(item.getStatus(), 4)).count();
|
|
|
|
// if (count > 0) {
|
|
|
|
// return ZDResponse.error("仅支持已下架的场景进行删除操作");
|
|
|
|
|