增加导出图片接口

master
gongzhenkun 2 years ago
parent e7fd283477
commit a3226b3ebe

@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TImage;
import com.ruoyi.system.domain.TRecord;
@ -21,12 +22,16 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -48,6 +53,9 @@ public class TRecordController extends BaseController
@Resource
private ITImageService imageService;
@Value("${export.img.url}")
private String imgUrl;
/**
*
*/
@ -113,6 +121,44 @@ public class TRecordController extends BaseController
util.exportExcel(response, list, "诊断记录信息数据");
}
/**
*
*/
@Log(title = "诊断记录信息导出", businessType = BusinessType.EXPORT)
@PostMapping("/exportImg")
public void exportImg(HttpServletResponse response, @RequestBody @Validated TRecordResultReq tRecord)
{
List<TImage> images = imageService.queryImagByExport(tRecord);
List<Map<String,Object>> exportInfo = new ArrayList<>();
if(CollectionUtils.isNotEmpty(images)){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
images.forEach(image -> {
Map<String,Object> map = new HashMap<>();
map.put("urlPath",imgUrl + image.getPath());
StringBuilder downloadPath = new StringBuilder();
downloadPath.append(image.getIdentifier());
downloadPath.append("_");
downloadPath.append(simpleDateFormat.format(image.getCreateTime()));
downloadPath.append("/");
if("sm_front".endsWith(image.getName())){
downloadPath.append("舌面原图.");
}else if("sx_front".endsWith(image.getName())){
downloadPath.append("舌下原图.");
}
downloadPath.append(StringUtils.substringAfterLast(image.getPath(), "."));
map.put("downloadPath",downloadPath.toString());
exportInfo.add(map);
});
}
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
try {
FileUtils.setAttachmentResponseHeader(response, "舌面舌下图片下载");
FileUtils.urlResourceWriteBytes(exportInfo, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*/

@ -137,5 +137,7 @@ aiPost:
port: 6000
url: /tongue/algo/sm_sx
export:
img:
url: https://tonguediag.jiicm.com/prod-api

@ -1,12 +1,16 @@
package com.ruoyi.common.utils.file;
import java.io.*;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -65,6 +69,87 @@ public class FileUtils
}
}
/**
* byte
*
* @param filePath
* @param os
* @return
*/
public static void urlResourceWriteBytes(String filePath, OutputStream os) throws IOException
{
InputStream fis = null;
ZipEntry zipEntry = null;
ZipOutputStream zipOutputStream = null;
try
{
URL file = new URL(filePath);
fis = file.openStream();
zipEntry = new ZipEntry(filePath);
zipOutputStream = new ZipOutputStream(os);
zipOutputStream.putNextEntry(zipEntry);
byte[] b = new byte[1024];
int length;
while ((length = fis.read(b)) > 0)
{
zipOutputStream.write(b, 0, length);
}
}
catch (IOException e)
{
throw e;
}
finally
{
zipOutputStream.closeEntry();
IOUtils.close(zipOutputStream);
IOUtils.close(os);
IOUtils.close(fis);
}
}
/**
* byte
*
* @param filePathList
* @param os
* @return
*/
public static void urlResourceWriteBytes(List<Map<String,Object>> filePathList, OutputStream os) throws IOException
{
// InputStream fis = null;
BufferedInputStream buf = null;
ZipEntry zipEntry = null;
ZipOutputStream zipOutputStream = new ZipOutputStream(os);
try
{
for(Map<String,Object> filePath:filePathList){
URL file = new URL(filePath.get("urlPath").toString());
// fis = file.openStream();
buf = new BufferedInputStream(file.openStream());
zipEntry = new ZipEntry(filePath.get("downloadPath").toString());
zipOutputStream.putNextEntry(zipEntry);
byte[] b = new byte[1024];
int length;
while ((length = buf.read(b)) > 0)
{
zipOutputStream.write(b, 0, length);
}
}
}
catch (IOException e)
{
throw e;
}
finally
{
zipOutputStream.closeEntry();
IOUtils.close(zipOutputStream);
IOUtils.close(os);
IOUtils.close(buf);
}
}
/**
*
*

@ -30,7 +30,17 @@ public class TImage extends BaseEntity
@Excel(name = "名称")
private String name;
public void setId(Long id)
private String identifier;
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getIdentifier() {
return identifier;
}
public void setId(Long id)
{
this.id = id;
}

@ -2,6 +2,7 @@ package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.TImage;
import com.ruoyi.system.domain.req.TRecordResultReq;
/**
* Mapper
@ -60,4 +61,6 @@ public interface TImageMapper
public int deleteTImageByIds(Long[] ids);
int deleteTImageByThirdId(Long id);
List<TImage> queryImagByExport(TRecordResultReq tRecord);
}

@ -2,6 +2,7 @@ package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.TImage;
import com.ruoyi.system.domain.req.TRecordResultReq;
/**
* Service
@ -60,4 +61,6 @@ public interface ITImageService
public int deleteTImageById(Long id);
int deleteTImageByThirdId(Long id);
List<TImage> queryImagByExport(TRecordResultReq tRecord);
}

@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.req.TRecordResultReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TImageMapper;
@ -98,4 +99,9 @@ public class TImageServiceImpl implements ITImageService
{
return tImageMapper.deleteTImageByThirdId(id);
}
@Override
public List<TImage> queryImagByExport(TRecordResultReq tRecord) {
return tImageMapper.queryImagByExport(tRecord);
}
}

@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="path" column="path" />
<result property="name" column="name" />
<result property="createTime" column="create_time" />
<result property="identifier" column="identifier" />
</resultMap>
<sql id="selectTImageVo">
@ -72,4 +73,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteTImageByThirdId" parameterType="Long">
delete from t_image where third_id = #{id}
</delete>
<select id="queryImagByExport" parameterType="TRecordResultReq" resultMap="TImageResult">
SELECT
ti.id,
ti.third_id,
ti.path,
ti.name,
ti.create_time,
tp.identifier
FROM
t_record tr
LEFT JOIN t_doctor td ON tr.doctor_id = td.id
LEFT JOIN t_patient tp ON tr.patient_id = tp.id
LEFT JOIN t_hospital th ON tr.hospital_id = th.id
LEFT JOIN t_image ti ON tr.id = ti.third_id
where ti.`name` in ('sm_front','sx_front')
<if test="name != null and name != ''"> and tp.name like concat('%', #{name}, '%')</if>
<if test="doctorId != null "> and tr.doctor_id = #{doctorId}</if>
<if test="hospitalId != null "> and tr.hospital_id = #{hospitalId}</if>
<if test="status != null and status != ''"> and tr.status = #{status}</if>
<if test="doctorName != null and doctorName != ''"> and td.name like concat('%', #{doctorName}, '%')</if>
<if test="age !=null and age != ''">
and tp.age between
<foreach item="item" collection="age.split('-')" separator="and">
#{item}
</foreach>
</if>
<if test="sex !=null and sex !=''">and tp.sex = #{sex} </if>
<if test="identifier !=null and identifier != ''">and tp.identifier like concat('%', #{identifier}, '%')</if>
<if test="delFlag != null and delFlag != ''">
and tr.del_flag = #{delFlag}
</if>
<if test="createTime != null and createTime !='' and createTime != 'all'">
and DATE_FORMAT(tp.create_time,'%Y-%m') = #{createTime}
</if>
<if test="createTime == null or createTime ==''">
and to_days(tr.create_time) = to_days(now())
</if>
<if test="startTime != null and startTime != '' and endTime == null "> and tr.create_time &gt;= #{startTime}</if>
<if test="startTime == null and endTime != '' and endTime != null "> and tr.create_time &lt;= #{endTime}</if>
<if test="startTime != null and endTime != null "> and tr.create_time between #{startTime} and #{endTime}</if>
<if test="patientAge != null"> and tp.age = #{patientAge} </if>
<if test="doctorOder !=null and doctorOder !=''" >order by tr.create_time ${doctorOder}</if>
<if test="firstVisitOder!=null and firstVisitOder !=''" >order by tp.create_time ${firstVisitOder}</if>
</select>
</mapper>

Loading…
Cancel
Save