package com.doumee.api.web;
|
|
import cn.hutool.http.server.HttpServerResponse;
|
import com.alibaba.fastjson.JSONObject;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.annotation.trace.Trace;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.ApiResponse;
|
import com.doumee.core.oss.FileModel;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.DateUtil;
|
import com.doumee.dao.business.model.Bookings;
|
import com.doumee.dao.system.model.SystemDictData;
|
import com.doumee.dao.web.response.MonthDataResponse;
|
import com.doumee.service.business.UtilService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import okhttp3.OkHttpClient;
|
import okhttp3.Request;
|
import okhttp3.Response;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.imageio.ImageIO;
|
import javax.servlet.http.HttpServletResponse;
|
import java.awt.image.RenderedImage;
|
import java.io.*;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* Created by IntelliJ IDEA.
|
*
|
* @Author : Rk
|
* @create 2023/5/8 18:25
|
*/
|
@Api(tags = "99、帮助业务")
|
@Trace(exclude = true)
|
@RestController
|
@RequestMapping("/web/util")
|
@Slf4j
|
public class UtilApi extends ApiController{
|
|
@Autowired
|
private UtilService utilService;
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@ApiOperation(value = "查询字典值数据", notes = "小程序端")
|
@GetMapping("/getSystemDictData")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "query", dataType = "String", name = "label", value = "数据字典值", required = true),
|
@ApiImplicitParam(paramType = "query", dataType = "String", name = "dictCode", value = "系统字典值", required = true)
|
})
|
public ApiResponse<SystemDictData> getSystemDictData(@RequestParam String dictCode, @RequestParam String label) {
|
return ApiResponse.success("生成成功",systemDictDataBiz.queryByCode(dictCode,label));
|
}
|
|
|
|
@ApiOperation(value = "获取分享小程序二维码(base64格式,img标签src指定)", notes = "小程序端")
|
@GetMapping("/generate")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "bookingsId", value = "会议主键", required = true),
|
@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户主键", required = true)
|
})
|
public ApiResponse<String> generate(@RequestParam Integer bookingsId,@RequestParam Integer userId) {
|
return ApiResponse.success("生成成功",utilService.generate(bookingsId,userId));
|
}
|
|
@ApiOperation(value = "获取分享小程序二维码(图片流,img标签src指定)", notes = "小程序端")
|
@GetMapping("/generateImg")
|
@ApiImplicitParams({
|
@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "bookingsId", value = "会议主键", required = true),
|
@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户主键", required = true)
|
})
|
public void generateImg(@RequestParam Integer bookingsId, @RequestParam Integer userId, HttpServletResponse response) {
|
try{
|
response.setHeader("Cache-Control", "no-store, no-cache");
|
response.setContentType("image/jpeg");
|
InputStream inputStream = utilService.generateImgStream(bookingsId,userId);
|
ImageIO.write(ImageIO.read(inputStream),"png",response.getOutputStream());
|
}catch (Exception e){
|
e.printStackTrace();
|
|
}
|
// OutputStream out = null;
|
// try{
|
// response.setHeader("Cache-Control", "no-store, no-cache");
|
// response.setContentType("image/jpeg");
|
// InputStream inputStream = utilService.generateImgStream(bookingsId,userId);
|
// out = response.getOutputStream();
|
// int len = 0;
|
// byte[] b = new byte[1024];
|
// while ((len = inputStream.read(b)) != -1) {
|
// out.write(b, 0, len);
|
// }
|
// out.flush();
|
// }catch (Exception e){
|
// e.printStackTrace();
|
// }finally {
|
// try {
|
// if (out != null) {
|
// out.close();
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// }
|
|
}
|
|
|
|
}
|