bug修复
This commit is contained in:
parent
ffe6fe38a9
commit
c9747cfbef
@ -1,7 +1,6 @@
|
||||
package com.zhgd.xmgl.modules.quality.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhgd.annotation.DataScope;
|
||||
import com.zhgd.xmgl.modules.quality.entity.QualityRegion;
|
||||
import com.zhgd.xmgl.modules.quality.entity.vo.QualityRegionVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -26,7 +25,7 @@ public interface QualityRegionMapper extends BaseMapper<QualityRegion> {
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@DataScope(includeTable = "enterprise_info")
|
||||
// @DataScope(includeTable = "enterprise_info")
|
||||
List<QualityRegionVo> queryList(Map<String, Object> map);
|
||||
|
||||
/**
|
||||
|
||||
@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gexin.fastjson.serializer.SerializerFeature;
|
||||
@ -343,10 +344,9 @@ public class RiskListPointController {
|
||||
public Result delFromMonthlyBatch(@ApiIgnore @RequestBody HashMap<String, Object> param) {
|
||||
String ids = MapUtils.getString(param, "ids");
|
||||
if (StrUtil.isNotBlank(ids)) {
|
||||
// riskListSourceService.update(new LambdaUpdateWrapper<RiskListSource>()
|
||||
// .set(RiskListSource::get,)
|
||||
// .in(RiskListSource::getPointId, StrUtil.split(ids, ",")));
|
||||
|
||||
riskListPointService.update(new LambdaUpdateWrapper<RiskListPoint>()
|
||||
.set(RiskListPoint::getMonthlyId, null)
|
||||
.in(RiskListPoint::getId, StrUtil.split(ids, ",")));
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ -31,10 +31,7 @@ import com.zhgd.xmgl.modules.worker.entity.vo.PresentDayByMonthVo;
|
||||
import com.zhgd.xmgl.modules.worker.entity.vo.SafetyPerformanceAnalysisVo;
|
||||
import com.zhgd.xmgl.modules.worker.service.*;
|
||||
import com.zhgd.xmgl.security.util.SecurityUtils;
|
||||
import com.zhgd.xmgl.util.EasyPoiUtil;
|
||||
import com.zhgd.xmgl.util.ExcelUtils;
|
||||
import com.zhgd.xmgl.util.Fileutils;
|
||||
import com.zhgd.xmgl.util.MapBuilder;
|
||||
import com.zhgd.xmgl.util.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
@ -563,6 +560,7 @@ public class WorkerAttendanceController {
|
||||
param.put("pageSize", -1);
|
||||
List<WorkerAttendanceVo> records = workerAttendanceService.selectWorkerAttendancePage(param).getRecords();
|
||||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||||
ArrayList<byte[]> imageBytesList = new ArrayList<>();
|
||||
for (int i = 0; i < records.size(); i++) {
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
WorkerAttendanceVo vo = records.get(i);
|
||||
@ -573,7 +571,7 @@ public class WorkerAttendanceController {
|
||||
objectMap.put("createTime", vo.getCreateTime());
|
||||
objectMap.put("projectSn", vo.getProjectSn());
|
||||
objectMap.put("cardType", getType(vo.getCardType()));
|
||||
objectMap.put("imageUrl", EasyPoiUtil.getImageEntityByXls(vo.getImageUrl()));
|
||||
// objectMap.put("imageUrl", EasyPoiUtil.getImageEntityByXls(vo.getImageUrl()));
|
||||
objectMap.put("attendanceType", vo.getAttendanceType());
|
||||
objectMap.put("passagewayName", vo.getPassagewayName());
|
||||
objectMap.put("attendanceStatus", vo.getAttendanceStatus());
|
||||
@ -593,12 +591,20 @@ public class WorkerAttendanceController {
|
||||
objectMap.put("departmentTeamName", vo.getDepartmentTeamName());
|
||||
objectMap.put("mockTime", vo.getMockTime());
|
||||
objectMap.put("enterpriseName", vo.getEnterpriseName());
|
||||
byte[] bytes = new byte[0];
|
||||
try {
|
||||
bytes = cn.hutool.core.io.FileUtil.readBytes(PathUtil.getBasePath() + "/" + vo.getImageUrl());
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
imageBytesList.add(bytes);
|
||||
}
|
||||
listMap.add(objectMap);
|
||||
}
|
||||
map.put("listMap", listMap);
|
||||
templateUrl = Fileutils.getExportTemplateFile("excel/人员考勤记录导出.xlsx").getAbsolutePath();
|
||||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
|
||||
ExcelUtils.exportPicture(workbook, 0, imageBytesList, 1, 8, 1);
|
||||
ExcelUtils.downLoadExcel("风险点清单导出模板.xlsx", response, workbook);
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
|
||||
@ -1,15 +1,23 @@
|
||||
package com.zhgd.xmgl.modules.xz.security.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zhgd.annotation.OperLog;
|
||||
import com.zhgd.file.FileUtil;
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||||
import com.zhgd.xmgl.base.entity.vo.SectorVo;
|
||||
import com.zhgd.xmgl.base.entity.vo.TrendOneVo;
|
||||
import com.zhgd.xmgl.constant.Cts;
|
||||
import com.zhgd.xmgl.modules.basicdata.constant.DictionaryConstant;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.DictionaryItem;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.impl.DictionaryItemServiceImpl;
|
||||
import com.zhgd.xmgl.modules.dangerous.service.IDangerousEngineeringRecordService;
|
||||
import com.zhgd.xmgl.modules.risk.entity.RiskListSource;
|
||||
import com.zhgd.xmgl.modules.risk.entity.vo.RiskListSourceVo;
|
||||
@ -21,14 +29,14 @@ import com.zhgd.xmgl.modules.xz.security.entity.dto.XzSecurityDepartmentRectifie
|
||||
import com.zhgd.xmgl.modules.xz.security.entity.dto.XzSecurityQualityInspectionRecordSourceAddDto;
|
||||
import com.zhgd.xmgl.modules.xz.security.entity.vo.*;
|
||||
import com.zhgd.xmgl.modules.xz.security.service.IXzSecurityQualityInspectionRecordService;
|
||||
import com.zhgd.xmgl.util.MapBuilder;
|
||||
import com.zhgd.xmgl.util.MessageUtil;
|
||||
import com.zhgd.xmgl.util.*;
|
||||
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 org.apache.commons.collections.MapUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@ -37,12 +45,11 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@ -68,6 +75,9 @@ public class XzSecurityQualityInspectionRecordController {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private IRiskListSourceService riskListSourceService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private DictionaryItemServiceImpl dictionaryItemService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@ -579,4 +589,163 @@ public class XzSecurityQualityInspectionRecordController {
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "导出潮州项目隐患统计汇总excel表", notes = "导出潮州项目隐患统计汇总excel表", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"),
|
||||
})
|
||||
@PostMapping(value = "/exportXls")
|
||||
public void exportXls(HttpServletResponse response, @RequestBody HashMap<String, Object> param) {
|
||||
String templateUrl = null;
|
||||
String projectSn = MapUtils.getString(param, "projectSn");
|
||||
Map<Integer, Map<String, Object>> root = new HashMap<>(4);
|
||||
Map<String, DictionaryItem> priorityNameDicNameMap = dictionaryItemService.getDictDataMapByProjectSn(DictionaryConstant.XZ_SECURITY_DANGER_ITEM_RECORD_PRIORITY_NAME_DIC, null);
|
||||
Map<String, DictionaryItem> dictDataMap = dictionaryItemService.getDictDataMapByProjectSn(DictionaryConstant.XZ_SECURITY_QUALITY_INSPECTION_RECORD_DUTY_MAJOR, projectSn);
|
||||
try {
|
||||
ArrayList<byte[]> imageBytesList = new ArrayList<>();
|
||||
ArrayList<byte[]> rectifyAfterImageBytesList = new ArrayList<>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
param.put("pageNo", 1);
|
||||
param.put("pageSize", -1);
|
||||
List<XzSecurityQualityInspectionRecordVo> records = qualityInspectionRecordService.selectQualityInspectionRecordPage(param).getPage().getRecords();
|
||||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||||
for (int i = 0; i < records.size(); i++) {
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
XzSecurityQualityInspectionRecordVo vo = records.get(i);
|
||||
objectMap.put("inspectManName", vo.getInspectManName());
|
||||
objectMap.put("createEnterpriseName", vo.getCreateEnterpriseName());
|
||||
objectMap.put("verifyManName", vo.getVerifyManName());
|
||||
objectMap.put("notifyPersonName", vo.getNotifyPersonName());
|
||||
objectMap.put("enterpriseName", vo.getEnterpriseName());
|
||||
objectMap.put("fullName", vo.getFullName());
|
||||
objectMap.put("routineCheckName", vo.getRoutineCheckName());
|
||||
objectMap.put("changeName", vo.getChangeName());
|
||||
objectMap.put("reviewName", vo.getReviewName());
|
||||
objectMap.put("overTime", vo.getOverTime());
|
||||
objectMap.put("problemDescription", vo.getProblemDescription());
|
||||
objectMap.put("dangerName", vo.getDangerName());
|
||||
objectMap.put("dangerItemName", vo.getDangerItemName());
|
||||
objectMap.put("engineeringName", vo.getEngineeringName());
|
||||
objectMap.put("jobApplicationUnitName", vo.getJobApplicationUnitName());
|
||||
objectMap.put("workTicketCode", vo.getWorkTicketCode());
|
||||
objectMap.put("deductScore", vo.getDeductScore());
|
||||
objectMap.put("mainEnterpriseName", vo.getMainEnterpriseName());
|
||||
objectMap.put("id", vo.getId());
|
||||
objectMap.put("regionId", vo.getRegionId());
|
||||
objectMap.put("regionName", vo.getRegionName());
|
||||
objectMap.put("remark", vo.getRemark());
|
||||
objectMap.put("dangerDesc", vo.getDangerDesc());
|
||||
objectMap.put("dangerItemContent", vo.getDangerItemContent());
|
||||
objectMap.put("dangerItemId", vo.getDangerItemId());
|
||||
objectMap.put("dangerTypeId", vo.getDangerTypeId());
|
||||
objectMap.put("level", vo.getLevel());
|
||||
objectMap.put("measurePoints", vo.getMeasurePoints());
|
||||
objectMap.put("urgentLevel", vo.getUrgentLevel());
|
||||
//状态,2待整改,3待复查,4待核验,5合格,6已撤回
|
||||
objectMap.put("status", getStatusText(vo.getStatus()));
|
||||
objectMap.put("notifyPerson", vo.getNotifyPerson());
|
||||
objectMap.put("creatorId", vo.getCreatorId());
|
||||
objectMap.put("createTime", DateUtil.format(DateUtil.parseDateTime(vo.getCreateTime()), "yyyy.MM.dd"));
|
||||
objectMap.put("changeId", vo.getChangeId());
|
||||
objectMap.put("changeLimitTime", vo.getChangeLimitTime());
|
||||
objectMap.put("inspectManId", vo.getInspectManId());
|
||||
objectMap.put("inspectTime", vo.getInspectTime());
|
||||
objectMap.put("recordType", vo.getRecordType());
|
||||
objectMap.put("fileUrl", vo.getFileUrl());
|
||||
objectMap.put("routineId", vo.getRoutineId());
|
||||
objectMap.put("completeTime", vo.getCompleteTime());
|
||||
objectMap.put("isDele", vo.getIsDele());
|
||||
objectMap.put("projectSn", vo.getProjectSn());
|
||||
objectMap.put("taskId", vo.getTaskId());
|
||||
objectMap.put("itemId", vo.getItemId());
|
||||
objectMap.put("subsectionId", vo.getSubsectionId());
|
||||
objectMap.put("subentryId", vo.getSubentryId());
|
||||
objectMap.put("floor", vo.getFloor());
|
||||
objectMap.put("addedDescription", vo.getAddedDescription());
|
||||
objectMap.put("engineeringId", vo.getEngineeringId());
|
||||
objectMap.put("type", vo.getType());
|
||||
objectMap.put("dutyMajor", Optional.ofNullable(dictDataMap.get(vo.getDutyMajor())).map(m -> m.getName()).orElse(null));
|
||||
objectMap.put("detailPlace", vo.getDetailPlace());
|
||||
objectMap.put("priorityNameDic", Optional.ofNullable(priorityNameDicNameMap.get(vo.getPriorityNameDic())).map(m -> m.getName()).orElse(null));
|
||||
objectMap.put("subsectionName", vo.getSubsectionName());
|
||||
objectMap.put("subentryName", vo.getSubentryName());
|
||||
objectMap.put("safeWatchAlarmExceedMinute", vo.getSafeWatchAlarmExceedMinute());
|
||||
objectMap.put("zgRectifyTime", vo.getZgRectifyTime());
|
||||
objectMap.put("zgFileUrl", vo.getZgFileUrl());
|
||||
objectMap.put("zgAdditionalRemarks", vo.getZgAdditionalRemarks());
|
||||
objectMap.put("fcRectifyTime", vo.getFcRectifyTime());
|
||||
objectMap.put("fcFileUrl", vo.getFcFileUrl());
|
||||
objectMap.put("fcAdditionalRemarks", vo.getFcAdditionalRemarks());
|
||||
objectMap.put("hyRectifyTime", vo.getHyRectifyTime());
|
||||
objectMap.put("hyFileUrl", vo.getHyFileUrl());
|
||||
objectMap.put("hyAdditionalRemarks", vo.getHyAdditionalRemarks());
|
||||
objectMap.put("violatorId", vo.getViolatorId());
|
||||
objectMap.put("regionIds", vo.getRegionIds());
|
||||
objectMap.put("reviewIds", vo.getReviewIds());
|
||||
objectMap.put("verifyManIds", vo.getVerifyManIds());
|
||||
objectMap.put("enterpriseIds", vo.getEnterpriseIds());
|
||||
objectMap.put("enterpriseSns", vo.getEnterpriseSns());
|
||||
objectMap.put("regionNames", vo.getRegionNames());
|
||||
objectMap.put("reviewNames", vo.getReviewNames());
|
||||
objectMap.put("verifyManNames", vo.getVerifyManNames());
|
||||
objectMap.put("enterpriseNames", vo.getEnterpriseNames());
|
||||
objectMap.put("no", i + 1);
|
||||
byte[] bytes = new byte[0];
|
||||
try {
|
||||
bytes = cn.hutool.core.io.FileUtil.readBytes(PathUtil.getBasePath() + "/" + vo.getImageUrl());
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
imageBytesList.add(bytes);
|
||||
}
|
||||
bytes = new byte[0];
|
||||
try {
|
||||
bytes = cn.hutool.core.io.FileUtil.readBytes(PathUtil.getBasePath() + "/" + vo.getRectifyAfterImage());
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
rectifyAfterImageBytesList.add(bytes);
|
||||
}
|
||||
// objectMap.put("imageUrl", EasyPoiUtil.getImageEntityByXls(vo.getImageUrl()));
|
||||
// objectMap.put("rectifyAfterImage", EasyPoiUtil.getImageEntityByXls(vo.getRectifyAfterImage()));
|
||||
List<String> split = StrUtil.split(vo.getDangerItemContent(), "/");
|
||||
objectMap.put("yhdl", CollUtil.get(split, 0));
|
||||
objectMap.put("yhxl", CollUtil.get(split, 1));
|
||||
listMap.add(objectMap);
|
||||
}
|
||||
map.put("listMap", listMap);
|
||||
templateUrl = Fileutils.getExportTemplateFile("excel/潮州项目隐患统计汇总表.xlsx").getAbsolutePath();
|
||||
root.put(0, map);
|
||||
TemplateExportParams params = new TemplateExportParams(templateUrl, true);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(root, params);
|
||||
//隐患图片
|
||||
ExcelUtils.exportPicture(workbook, 0, imageBytesList, 1, 3, 1);
|
||||
//整改图片
|
||||
ExcelUtils.exportPicture(workbook, 0, rectifyAfterImageBytesList, 1, 9, 1);
|
||||
ExcelUtils.downLoadExcel("潮州项目隐患统计汇总表.xlsx", response, workbook);
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
throw new OpenAlertException("系统错误");
|
||||
} finally {
|
||||
if (templateUrl != null) {
|
||||
FileUtil.deleteFile(templateUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getStatusText(Integer status) {
|
||||
if (status == null) {
|
||||
return "";
|
||||
}
|
||||
if (status == 2) {
|
||||
return "待整改";
|
||||
} else if (status == 3) {
|
||||
return "待复查";
|
||||
} else if (status == 4) {
|
||||
return "待核验";
|
||||
} else if (status == 5) {
|
||||
return "合格";
|
||||
} else if (status == 6) {
|
||||
return "已撤回";
|
||||
} else {
|
||||
return "未知状态";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,4 +352,8 @@ public class XzSecurityQualityInspectionRecord implements Serializable {
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "合作单位名称s(多个,分隔)")
|
||||
private String enterpriseNames;
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "草稿id")
|
||||
private String draftId;
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -181,6 +182,9 @@ public class XzSecurityQualityInspectionRecordServiceImpl extends ServiceImpl<Xz
|
||||
@Lazy
|
||||
@Autowired
|
||||
private IDictionaryItemService dictionaryItemService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private IXzSecurityQualityInspectionRecordDraftService xzSecurityQualityInspectionRecordDraftService;
|
||||
|
||||
private static List<Long> getChildrenByQualityRegionId(Long regionId, List<QualityRegion> all) {
|
||||
ArrayList<Long> list = new ArrayList<>();
|
||||
@ -490,6 +494,12 @@ public class XzSecurityQualityInspectionRecordServiceImpl extends ServiceImpl<Xz
|
||||
.in(EnterpriseInfo::getId, eids)).stream().map(EnterpriseInfo::getEnterpriseName).collect(Collectors.joining(","));
|
||||
record.setId(null);
|
||||
xzSecurityQualityInspectionRecordMapper.insert(record);
|
||||
if (record.getDraftId() != null) {
|
||||
xzSecurityQualityInspectionRecordDraftService.update(null, new LambdaUpdateWrapper<XzSecurityQualityInspectionRecordDraft>()
|
||||
.set(XzSecurityQualityInspectionRecordDraft::getIsGenerate, 1)
|
||||
.eq(XzSecurityQualityInspectionRecordDraft::getId, record.getDraftId())
|
||||
);
|
||||
}
|
||||
saveBindData(record);
|
||||
if (Objects.equals(record.getRecordType(), XzSecurityQualityInspectionRecordRecordTypeEnum.DANGER.getValue()) && Objects.equals(record.getStatus(), XzSecurityQualityInspectionRecordStatusEnum.NOT_RECTIFIED.getValue())) {
|
||||
noticeService.addUserNoticeAndApp(record.getChangeId(), "安全管理待整改", "您有一条安全检查待整改,问题:" + record.getDangerItemContent(), "10",
|
||||
|
||||
@ -12,13 +12,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -871,6 +870,105 @@ public class ExcelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出图片到excel
|
||||
*
|
||||
* @param workbook 工作簿
|
||||
* @param sheetIndex 工作表索引
|
||||
* @param bytesList 导出的图片字节数组列表
|
||||
* @param startRow 开始行
|
||||
* @param startCol 开始列
|
||||
* @param direction 方向:1纵向2横向
|
||||
*/
|
||||
public static void exportPicture(Workbook workbook, int sheetIndex, List<byte[]> bytesList,
|
||||
int startRow, int startCol, int direction) {
|
||||
if (workbook == null || bytesList == null || bytesList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(sheetIndex);
|
||||
if (sheet == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
||||
int rowIndex = startRow;
|
||||
int colIndex = startCol;
|
||||
|
||||
for (byte[] bytes : bytesList) {
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) {
|
||||
// 获取图片格式(简单判断,实际可能需要更复杂的检测)
|
||||
int pictureType = getPictureType(bytes);
|
||||
|
||||
// 添加图片到工作簿
|
||||
int pictureIndex = workbook.addPicture(bytes, pictureType);
|
||||
|
||||
// 创建锚点定位图片
|
||||
ClientAnchor anchor;
|
||||
if (workbook instanceof XSSFWorkbook) {
|
||||
anchor = new XSSFClientAnchor();
|
||||
} else if (workbook instanceof HSSFWorkbook) {
|
||||
anchor = new HSSFClientAnchor();
|
||||
} else {
|
||||
anchor = workbook.getCreationHelper().createClientAnchor();
|
||||
}
|
||||
|
||||
// 设置图片位置
|
||||
anchor.setCol1(colIndex);
|
||||
anchor.setRow1(rowIndex);
|
||||
anchor.setCol2(colIndex + 1); // 默认占1列宽度
|
||||
anchor.setRow2(rowIndex + 1); // 默认占1行高度
|
||||
|
||||
// 插入图片
|
||||
drawing.createPicture(anchor, pictureIndex);
|
||||
|
||||
// 根据方向调整下一个图片的位置
|
||||
if (direction == 1) {
|
||||
// 纵向排列:向下移动一行
|
||||
rowIndex++;
|
||||
} else {
|
||||
// 横向排列:向右移动一列
|
||||
colIndex++;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据图片字节数组判断图片类型
|
||||
*/
|
||||
private static int getPictureType(byte[] bytes) {
|
||||
if (bytes.length < 4) {
|
||||
return Workbook.PICTURE_TYPE_PNG;
|
||||
}
|
||||
|
||||
// 检查文件头标识
|
||||
if (bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xD8) {
|
||||
return Workbook.PICTURE_TYPE_JPEG;
|
||||
} else if (bytes[0] == (byte) 0x89 && bytes[1] == (byte) 0x50 &&
|
||||
bytes[2] == (byte) 0x4E && bytes[3] == (byte) 0x47) {
|
||||
return Workbook.PICTURE_TYPE_PNG;
|
||||
} else if (bytes[0] == (byte) 0x42 && bytes[1] == (byte) 0x4D) {
|
||||
return Workbook.PICTURE_TYPE_DIB;
|
||||
} else if (bytes[0] == (byte) 0x00 && bytes[1] == (byte) 0x00 &&
|
||||
bytes[2] == (byte) 0x01 && bytes[3] == (byte) 0x00) {
|
||||
return Workbook.PICTURE_TYPE_EMF;
|
||||
} else if (bytes[0] == (byte) 0x00 && bytes[1] == (byte) 0x00 &&
|
||||
bytes[2] == (byte) 0x02 && bytes[3] == (byte) 0x00) {
|
||||
return Workbook.PICTURE_TYPE_WMF;
|
||||
}
|
||||
|
||||
// 默认返回PNG类型
|
||||
return Workbook.PICTURE_TYPE_PNG;
|
||||
}
|
||||
|
||||
// // 示例用法
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
|
||||
Binary file not shown.
BIN
src/main/resources/excel/潮州项目隐患统计汇总表.xlsx
Normal file
BIN
src/main/resources/excel/潮州项目隐患统计汇总表.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user