diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/PerformanceManagementController.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/PerformanceManagementController.java index 3b80993..d003bb8 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/PerformanceManagementController.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/PerformanceManagementController.java @@ -1,6 +1,9 @@ package org.dromara.platform.controller; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.time.LocalDate; import java.util.List; import com.alibaba.excel.EasyExcel; @@ -10,6 +13,7 @@ import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import lombok.extern.slf4j.Slf4j; import org.dromara.platform.domain.PerformanceManagement; +import org.dromara.platform.domain.ProjectManager; import org.dromara.platform.listener.PerformanceManagementListener; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; @@ -58,9 +62,20 @@ public class PerformanceManagementController extends BaseController { @SaCheckPermission("platform:management:export") @Log(title = "考核管理", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(PerformanceManagementBo bo, HttpServletResponse response) { + public void export(PerformanceManagementBo bo, HttpServletResponse response) throws IOException { List list = performanceManagementService.queryList(bo); - ExcelUtil.exportExcel(list, "考核管理", PerformanceManagementVo.class, response); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String flag = "考核管理项"; + // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 + LocalDate currentDate = LocalDate.now(); + System.out.println("当前日期: " + currentDate); + String fileName = URLEncoder.encode( flag+currentDate, "UTF-8") + .replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(response.getOutputStream(), PerformanceManagementVo.class) + .sheet("考核管理"+currentDate) + .doWrite(list); } /** diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/WorkOrderInfoController.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/WorkOrderInfoController.java index 27b4755..cf57a77 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/WorkOrderInfoController.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/WorkOrderInfoController.java @@ -1,5 +1,7 @@ package org.dromara.platform.controller; +import java.net.URLEncoder; +import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/Attachment.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/Attachment.java new file mode 100644 index 0000000..69d1535 --- /dev/null +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/Attachment.java @@ -0,0 +1,32 @@ +package org.dromara.platform.domain; + +public class Attachment { + private String url; + private String name; + + // 默认构造函数 + public Attachment() {} + + // 带参数的构造函数 + public Attachment(String url, String name) { + this.url = url; + this.name = name; + } + + // Getter 和 Setter 方法 + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/AttachmentSerializer.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/AttachmentSerializer.java new file mode 100644 index 0000000..43d031a --- /dev/null +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/AttachmentSerializer.java @@ -0,0 +1,75 @@ +package org.dromara.platform.domain; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.List; + +public class AttachmentSerializer { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + /** + * 将List序列化为JSON字符串。 + * + * @param attachment 包含附件信息的列表 + * @return 序列化后的JSON字符串 + */ + public String serializeAttachments(List attachment) { + try { + // 使用ObjectMapper将List转换为JSON字符串 + return objectMapper.writeValueAsString(attachment); + } catch (JsonProcessingException e) { + // 处理可能发生的异常 + e.printStackTrace(); + // 根据实际情况决定如何处理错误,这里简单地返回null + return null; + } + } + + /** + * 将JSON字符串反序列化为List。 + * + * @param attachmentJson JSON格式的字符串 + * @return 反序列化后的List + */ + public List deserializeAttachments(String attachmentJson) { + try { + // 使用ObjectMapper将JSON字符串转换回List + return objectMapper.readValue(attachmentJson, new TypeReference>() {}); + } catch (JsonProcessingException e) { + // 处理可能发生的异常 + e.printStackTrace(); + // 根据实际情况决定如何处理错误,这里简单地返回null + return null; + } + } + + // 测试方法 + public static void main(String[] args) { + AttachmentSerializer serializer = new AttachmentSerializer(); + + // 创建一些模拟数据 + List attachmentList = List.of( + new Attachment("http://example.com/file1.pdf", "File One"), + new Attachment("http://example.com/file2.docx", "File Two") + ); + + // 序列化 + String serialized = serializer.serializeAttachments(attachmentList); + System.out.println(serialized); // 输出序列化后的JSON字符串 + + // 反序列化 + List deserializedAttachments = serializer.deserializeAttachments(serialized); + System.out.println("Deserialized:"); + if (deserializedAttachments != null) { + for (Attachment attachment : deserializedAttachments) { + System.out.println("URL: " + attachment.getUrl() + ", Name: " + attachment.getName()); + } + } else { + System.out.println("Failed to deserialize the JSON string."); + } + + } +} diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PerformanceManagement.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PerformanceManagement.java index 5b91a09..24725ff 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PerformanceManagement.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/PerformanceManagement.java @@ -8,6 +8,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serial; +import java.util.List; /** * 考核管理对象 performance_management @@ -30,6 +31,13 @@ public class PerformanceManagement extends TenantEntity { @TableId(value = "id") private String id; + + /** + *考核类型 + */ + @ExcelProperty("考核类型") + private String checkType; + /** * 类型(暂未使用) */ @@ -60,12 +68,6 @@ public class PerformanceManagement extends TenantEntity { @ExcelProperty("扣分标准") private String standards; - /** - * - */ - @ExcelProperty("考核类型") - private String checkType; - /** * 当前状态 */ diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/WorkOrderInfo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/WorkOrderInfo.java index 2d09037..3fade04 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/WorkOrderInfo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/WorkOrderInfo.java @@ -108,7 +108,10 @@ public class WorkOrderInfo extends TenantEntity { * 所属机构 */ private String organizationName; - + /** + * 文件名称 + */ + private String fileName; /** * 故障地点 */ diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/NoticeInfoBo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/NoticeInfoBo.java index 177a32d..85b9ecd 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/NoticeInfoBo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/NoticeInfoBo.java @@ -1,5 +1,7 @@ package org.dromara.platform.domain.bo; +import com.baomidou.mybatisplus.annotation.TableField; +import org.dromara.platform.domain.Attachment; import org.dromara.platform.domain.NoticeInfo; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.common.core.validate.AddGroup; @@ -9,6 +11,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; +import java.util.List; + /** * 公告通知信息业务对象 notice_info * @@ -60,8 +64,9 @@ public class NoticeInfoBo extends BaseEntity { /** * 附件 */ + @TableField(exist = false) //@NotBlank(message = "附件不能为空", groups = { AddGroup.class, EditGroup.class }) - private String attachment; + private List attachments; /** * 当前状态 @@ -70,4 +75,5 @@ public class NoticeInfoBo extends BaseEntity { private Long status; + } diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/WorkOrderInfoBo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/WorkOrderInfoBo.java index bce56e7..40edfb4 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/WorkOrderInfoBo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/bo/WorkOrderInfoBo.java @@ -148,4 +148,7 @@ public class WorkOrderInfoBo extends BaseEntity { * 处理时限 */ private int handleTime; + + private String fileName; + } diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/NoticeInfoVo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/NoticeInfoVo.java index 2f2a112..43aafcc 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/NoticeInfoVo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/NoticeInfoVo.java @@ -2,6 +2,7 @@ package org.dromara.platform.domain.vo; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; +import org.dromara.platform.domain.Attachment; import org.dromara.platform.domain.NoticeInfo; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; @@ -13,7 +14,7 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; import java.util.Date; - +import java.util.List; /** @@ -69,9 +70,12 @@ public class NoticeInfoVo implements Serializable { /** * 附件 */ - @ExcelProperty(value = "附件") + //@ExcelProperty(value = "附件") private String attachment; + @TableField(exist = false) + private List attachments; + /** * 当前状态 */ diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PerformanceManagementVo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PerformanceManagementVo.java index c9bf6d7..3e41e53 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PerformanceManagementVo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/PerformanceManagementVo.java @@ -1,5 +1,6 @@ package org.dromara.platform.domain.vo; +import com.alibaba.excel.annotation.ExcelIgnore; import com.fasterxml.jackson.annotation.JsonFormat; import org.dromara.platform.domain.PerformanceManagement; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; @@ -32,13 +33,19 @@ public class PerformanceManagementVo implements Serializable { /** * 唯一标识符 */ - @ExcelProperty(value = "唯一标识符") + //@ExcelProperty(value = "唯一标识符") + @ExcelIgnore private String id; - + /** + * 考核类型 + */ + @ExcelProperty(value = "考核类型") + private String checkType; /** * 类型 */ - @ExcelProperty(value = "类型") + //@ExcelProperty(value = "类型") + @ExcelIgnore private String type; /** @@ -65,16 +72,13 @@ public class PerformanceManagementVo implements Serializable { @ExcelProperty(value = "扣分标准") private String standards; - /** - * 考核类型 - */ - @ExcelProperty(value = "考核类型") - private String checkType; + /** * 当前状态 */ - @ExcelProperty(value = "当前状态") + //@ExcelProperty(value = "当前状态") + @ExcelIgnore private Long status; @ExcelProperty(value = "创建时间") diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/WorkOrderInfoVo.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/WorkOrderInfoVo.java index 8a5ac93..d03f36f 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/WorkOrderInfoVo.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/domain/vo/WorkOrderInfoVo.java @@ -116,8 +116,8 @@ public class WorkOrderInfoVo implements Serializable { /** * 故障图片Url */ - @Translation(type = TransConstant.OSS_ID_TO_URL, mapper = "faultImage") - private String faultImageUrl; +// @Translation(type = TransConstant.OSS_ID_TO_URL, mapper = "faultImage") +// private String faultImageUrl; /** * 维护要求 (0: 修复, 1: 新增, 2: 拆除, 3: 清除, 4: 其他) */ @@ -158,4 +158,5 @@ public class WorkOrderInfoVo implements Serializable { * 处理时限 */ private int handleTime; + private String fileName; } diff --git a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/NoticeInfoServiceImpl.java b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/NoticeInfoServiceImpl.java index 03674f0..073f842 100644 --- a/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/NoticeInfoServiceImpl.java +++ b/ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/service/impl/NoticeInfoServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.platform.service.impl; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; @@ -10,6 +11,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.platform.domain.Attachment; +import org.dromara.platform.domain.AttachmentSerializer; import org.springframework.stereotype.Service; import org.dromara.platform.domain.bo.NoticeInfoBo; import org.dromara.platform.domain.vo.NoticeInfoVo; @@ -29,6 +32,7 @@ import java.util.Collection; */ @RequiredArgsConstructor @Service +@Slf4j public class NoticeInfoServiceImpl implements INoticeInfoService { private final NoticeInfoMapper baseMapper; @@ -41,7 +45,15 @@ public class NoticeInfoServiceImpl implements INoticeInfoService { */ @Override public NoticeInfoVo queryById(String id){ - return baseMapper.selectVoById(id); + NoticeInfoVo noticeInfoVo = baseMapper.selectVoById(id); + String attachment = noticeInfoVo.getAttachment(); + if (StringUtils.isNotBlank(attachment)) { + AttachmentSerializer serializer = new AttachmentSerializer(); + List attachments = serializer.deserializeAttachments(attachment); + noticeInfoVo.setAttachments(attachments); + + } + return noticeInfoVo; } /** @@ -78,7 +90,7 @@ public class NoticeInfoServiceImpl implements INoticeInfoService { lqw.eq(StringUtils.isNotBlank(bo.getType()), NoticeInfo::getType, bo.getType()); lqw.eq(StringUtils.isNotBlank(bo.getHandler()), NoticeInfo::getHandler, bo.getHandler()); lqw.eq(StringUtils.isNotBlank(bo.getContent()), NoticeInfo::getContent, bo.getContent()); - lqw.eq(StringUtils.isNotBlank(bo.getAttachment()), NoticeInfo::getAttachment, bo.getAttachment()); + //lqw.eq(StringUtils.isNotBlank(bo.getAttachment()), NoticeInfo::getAttachment, bo.getAttachment()); lqw.eq(bo.getStatus() != null, NoticeInfo::getStatus, bo.getStatus()); return lqw; } @@ -95,6 +107,10 @@ public class NoticeInfoServiceImpl implements INoticeInfoService { LoginUser loginUser = LoginHelper.getLoginUser(); add.setHandler(loginUser.getNickname()); validEntityBeforeSave(add); + List attachments = bo.getAttachments(); + AttachmentSerializer serializer = new AttachmentSerializer(); + String serializedAttachment = serializer.serializeAttachments(attachments); + add.setAttachment(serializedAttachment); boolean flag = baseMapper.insert(add) > 0; if (flag) { bo.setId(add.getId());