Commit 9c68523f authored by 耿迪迪's avatar 耿迪迪

安检单导出问题修改

parent e22b53ae
......@@ -5,11 +5,13 @@ import cn.afterturn.easypoi.word.entity.MyXWPFDocument;
import cn.hutool.core.img.ImgUtil;
import com.zehong.common.config.ProjectNameConfig;
import com.zehong.common.exception.CustomException;
import com.zehong.common.utils.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
......@@ -81,7 +83,8 @@ public class InspectExportUtil {
InputStream source = this.getClass().getResourceAsStream("/excelTemplate/" + template);
MyXWPFDocument doc = new MyXWPFDocument(source);
WordExportUtil.exportWord07(doc,map);
String filename = (String) map.get("company") + map.get("createTime") + "安检单.docx";
String company = (String) map.get("company");
String filename = (StringUtils.isNotEmpty(company) ? company : (String) map.get("username")) + map.get("createTime") + "安检单.docx";
FileOutputStream out = new FileOutputStream(getExportAbsoluteFile(filename));
doc.write(out);
out.flush();
......@@ -182,26 +185,47 @@ public class InspectExportUtil {
// 得到图片的中心点
int width = image.getWidth();
int height = image.getHeight();
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
double rads = Math.toRadians(angle);
double sin = Math.abs(Math.sin(rads));
double cos = Math.abs(Math.cos(rads));
int newWidth = (int) Math.floor(width * cos + height * sin),
newHeight = (int) Math.floor(height * cos + width * sin);
int imageType = image.getType();
if(0 == imageType){
imageType = BufferedImage.TYPE_INT_ARGB;
}
// 创建一个新的图片用于保存旋转后的图片
BufferedImage rotatedImage = new BufferedImage(newWidth, newHeight, imageType);
if (width <= 0 || height <= 0) {
throw new IOException("图片尺寸异常: " + width + "x" + height);
}
if (newWidth < 1) newWidth = 1;
if (newHeight < 1) newHeight = 1;
// ==========================================
// 使用 Graphics2D 旋转(100% 稳定,不依赖浮点数精度)
// ==========================================
BufferedImage rotated = new BufferedImage(newWidth, newHeight, imageType);
Graphics2D g = rotated.createGraphics();
// 设置旋转的中心点
// 高质量渲染
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// 设置变换
AffineTransform at = new AffineTransform();
at.translate((newWidth - width) / 2, (newHeight - height) / 2);
at.rotate(Math.toRadians(angle), width / 2, height / 2);
at.translate((newWidth - width) / 2.0, (newHeight - height) / 2.0);
at.rotate(rads, width / 2.0, height / 2.0);
g.drawImage(image, at, null);
g.dispose();
// 转标准 RGB(避免后续 POI 插入 Excel 时出问题)
BufferedImage standard = new BufferedImage(newWidth, newHeight, imageType);
Graphics2D g2 = standard.createGraphics();
g2.drawImage(rotated, 0, 0, null);
g2.dispose();
// 执行旋转
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
rotatedImage = op.filter(image, rotatedImage);
return rotatedImage;
return standard;
}
/**
......
......@@ -194,7 +194,9 @@ public class TTaskInspectExportServiceImpl implements ITTaskInspectExportService
String dangerNumber = contentJson.getString("dangerNumber");
map.put("dangerNumber","0".equals(dangerNumber) ? true : false);
//map.put("zgDay",contentJson.getString("zgDay"));
map.put("qmUrl",contentJson.getString("qmUrl"));
if(StringUtils.isNotEmpty(contentJson.getString("qmUrl"))){
map.put("qmUrl",contentJson.getString("qmUrl"));
}
JSONObject userInfo = contentJson.getJSONObject("userInfo");
if(null != userInfo){
for(String userKey : userInfo.keySet()){
......@@ -281,14 +283,13 @@ public class TTaskInspectExportServiceImpl implements ITTaskInspectExportService
//user中获取
TBusiness businessInfo = tBusinessMapper.selectTBusinessById(businessInspectList.get(finalIndex).getReceiveId());
if(null != businessInfo){
map.put("company",businessInfo.getCompany());
map.put("username",businessInfo.getUsername());
map.put("address",businessInfo.getAddress());
map.put("usernum",businessInfo.getUsernum());
map.put("phone",businessInfo.getPhone());
}
//安检单中取
map.put("qitawentiText",obj.getJSONObject("qitawenti").getString("textarea"));
map.put("yijian",contentJson.getString("yijian"));
map.put("inspector",businessInspectList.get(finalIndex).getMemberName());
map.put("currentDate", new SimpleDateFormat("yyyy年MM月dd日").format(businessInspectList.get(finalIndex).getCreateTime()));
......@@ -302,7 +303,7 @@ public class TTaskInspectExportServiceImpl implements ITTaskInspectExportService
exportLog.setMemberId(businessInspectList.get(finalIndex).getMemberId());
exportLog.setType(businessInspectList.get(finalIndex).getType());
exportLog.setCreateTime(new Date());
exportLog.setFileName((String) map.get("company") + map.get("createTime") + "安检单.docx");
exportLog.setFileName((String) map.get("username") + map.get("createTime") + "安检单.docx");
map.put("exportLog",exportLog);
mapList.add(map);
} catch (Exception e) {
......@@ -382,7 +383,6 @@ public class TTaskInspectExportServiceImpl implements ITTaskInspectExportService
}
//安检单中取
map.put("qitawentiText",obj.getJSONObject("qitawenti").getString("textarea"));
map.put("yijian",contentJson.getString("yijian"));
map.put("inspector",industryQuarterInspectList.get(finalIndex).getMemberName());
map.put("currentDate", new SimpleDateFormat("yyyy年MM月dd日").format(industryQuarterInspectList.get(finalIndex).getCreateTime()));
......
......@@ -50,6 +50,7 @@
</if>
LEFT JOIN sys_user su ON su.user_id = ex.member_id
<where>
ex.file_name NOT LIKE 'null%';
<if test="taskId != null "> and ex.task_id = #{taskId}</if>
<if test="inspectId != null "> and ex.inspect_id = #{inspectId}</if>
<if test="memberId != null "> and ex.member_id = #{memberId}</if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment