Commit a84ffea7 by 黄明步

修改年月日调用记录导出、我的消息导出接口

parent 73304dc2
......@@ -8,32 +8,23 @@ import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.entity.DeriveCallRecord;
import com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils;
import com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService;
import com.gxmailu.ocrCloudPlatform.utils.DateUtils;
import com.gxmailu.ocrCloudPlatform.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.*;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -104,7 +95,7 @@ public class AppAbilityRecordAllController {
// 设置单元格样式
.registerWriteHandler(horizontalCellStyleStrategy)
.doWrite(callRecordList);
}catch (Exception e){
} catch (Exception e){
log.error("导出异常", e);
// 重置response
response.reset();
......
......@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@RestController
@Api("消息模块")
public class MessageController {
......@@ -31,6 +33,12 @@ public class MessageController {
return messageService.getMyMessageList(userMessageParam);
}
@ApiOperation("获取我的消息列表")
@GetMapping("exportMyMessageList")
public void exportMyMessageList(UserMessageParam userMessageParam, HttpServletResponse response){
messageService.exportMyMessageList(userMessageParam, response);
}
@ApiOperation("获取用户消息")
@GetMapping("getUserMessages")
public Result getUserMessages(UserMessage userMessage){
......
......@@ -69,14 +69,14 @@ public class RetransmissionController {
retransmissionService.downloadOfdNew(body, response);
}
@PostMapping("/ofs/api/sync/v1/ft/1001")
public OcrResult fullTextRecognition(String fileId, MultipartFile file, HttpServletRequest request) {
return retransmissionService.fullTextRecognition(fileId, file, request);
@PostMapping("/ofs/api/sync/v1/ft/{code}")
public OcrResult fullTextRecognition(@PathVariable("code") String code,String fileId, MultipartFile file, HttpServletRequest request) {
return retransmissionService.fullTextRecognition(code, fileId, file, request);
}
@PostMapping("/ofs/api/sync/v2/ft/1001")
public OcrResult fullTextRecognitionV2(String fileId, MultipartFile file, HttpServletRequest request) {
return retransmissionService.fullTextRecognitionV2(fileId, file, request);
@PostMapping("/ofs/api/sync/v2/ft/{code}")
public OcrResult fullTextRecognitionV2(@PathVariable("code") String code,String fileId, MultipartFile file, HttpServletRequest request) {
return retransmissionService.fullTextRecognitionV2(code, fileId, file, request);
}
@PostMapping("/ofs/api/sync/v1/kv/{code}")
......
package com.gxmailu.ocrCloudPlatform.excel.converter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
* 告警消息已读未读转换器
*
* @author Hmb
* @version 1.0.0
* @since 2024/1/21 14:35:30
*/
public class UserMessageConverter implements Converter<Boolean> {
/**
* Convert Java objects to excel objects
*
* @param value Java Data.NotNull.
* @param contentProperty Content property.Nullable.
* @param globalConfiguration Global configuration.NotNull.
* @return Data to put into a Excel
*/
@Override
public WriteCellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (value) {
return new WriteCellData<>("已读");
}
return new WriteCellData<>("未读");
}
}
package com.gxmailu.ocrCloudPlatform.excel.model;
import com.alibaba.excel.annotation.ExcelProperty;
import com.gxmailu.ocrCloudPlatform.excel.converter.UserMessageConverter;
import lombok.Data;
import java.util.Date;
/**
* @author Hmb
* @since 2024/1/22 17:55
*/
@Data
public class UserMessageModel {
@ExcelProperty(value = "标题")
private String title;
@ExcelProperty(value = "内容")
private String body;
@ExcelProperty(value = "是否已读", converter = UserMessageConverter.class)
private Boolean read;
@ExcelProperty(value = "发布人")
private String promulgator;
@ExcelProperty(value = "创建时间")
private Date pubDate;
}
......@@ -3,6 +3,7 @@ package com.gxmailu.ocrCloudPlatform.mapper;
import com.gxmailu.ocrCloudPlatform.dto.UserMessageParam;
import com.gxmailu.ocrCloudPlatform.entity.UserMessage;
import com.gxmailu.ocrCloudPlatform.excel.model.UserMessageModel;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
......@@ -26,4 +27,6 @@ public interface UserMessageMapper {
List<UserMessage> selectByUserMessage(UserMessage userMessage);
List<UserMessage> selectByUserMessageParam(UserMessageParam userMessageParam);
List<UserMessageModel> selectUserMessage(UserMessageParam userMessageParam);
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import com.gxmailu.ocrCloudPlatform.dto.UserMessageParam;
import com.gxmailu.ocrCloudPlatform.entity.UserMessage;
import com.gxmailu.ocrCloudPlatform.vo.Result;
import javax.servlet.http.HttpServletResponse;
public interface MessageService {
Result getUserMessages(UserMessage userMessage);
......@@ -18,4 +20,6 @@ public interface MessageService {
Result alertManagerMsg(JSONObject object);
Object sendMessage(JSONObject object);
void exportMyMessageList(UserMessageParam userMessageParam, HttpServletResponse response);
}
......@@ -54,7 +54,7 @@ public class CourtServiceImpl implements CourtService {
return Result.serverError("查询失败");
}
return Result.error("未找到相关数据");
return new Result(true, 0, "未找到相关数据", 0L, null);
}
@Override
......
......@@ -30,10 +30,8 @@ import com.gxmailu.ocrCloudPlatform.service.ConfigAbilityService;
import com.gxmailu.ocrCloudPlatform.service.ConfigApplicationService;
import com.gxmailu.ocrCloudPlatform.service.CourtService;
import com.gxmailu.ocrCloudPlatform.vo.BrokenLineData;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......
......@@ -3,8 +3,14 @@ package com.gxmailu.ocrCloudPlatform.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -14,6 +20,9 @@ import com.google.common.base.Joiner;
import com.gxmailu.ocrCloudPlatform.dto.MessageDto;
import com.gxmailu.ocrCloudPlatform.dto.UserMessageParam;
import com.gxmailu.ocrCloudPlatform.entity.*;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.excel.model.UserMessageModel;
import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils;
import com.gxmailu.ocrCloudPlatform.mapper.*;
import com.gxmailu.ocrCloudPlatform.service.MessageService;
import com.gxmailu.ocrCloudPlatform.vo.Result;
......@@ -26,10 +35,9 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
@Service
@Slf4j
......@@ -202,6 +210,44 @@ public class MessageServiceImpl implements MessageService {
}
}
@Override
public void exportMyMessageList(UserMessageParam userMessageParam, HttpServletResponse response) {
if (StringUtils.isEmpty(userMessageParam.getUsername())) {
log.error("用户名 [username] 不能为空");
}
try {
List<UserMessageModel> userMessages = userMessageMapper.selectUserMessage(userMessageParam);
userMessages.forEach(userMessage -> userMessage.setRead(BooleanUtil.isTrue(userMessage.getRead())));
// 导出逻辑
String fileName = "告警消息日志导出.xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 设置单元格样式策略
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(ExcelStyleUtils.getHeadStyle(), ExcelStyleUtils.getContentStyle());
EasyExcel.write(response.getOutputStream(), CallRecordModel.class)
.sheet("导出数据")
.head(UserMessageModel.class)
// 自动行宽策略
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 设置单元格样式
.registerWriteHandler(horizontalCellStyleStrategy)
.doWrite(userMessages);
} catch (Exception e) {
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
Map<String, String> map = MapUtils.newHashMap();
map.put("status", "500");
map.put("message", "导出失败,请联系管理员");
try {
response.getWriter().println(JSON.toJSONString(map));
} catch (IOException ex) {
log.error("", ex);
}
}
}
// 发送故障信息给相关人员
private void sendFaultMessage(Message message) {
Role role = roleMapper.selectOne(new LambdaQueryWrapper<Role>().eq(Role::getName, "inform"));
......
......@@ -26,7 +26,6 @@ import com.gxmailu.ocrCloudPlatform.service.ServerInfoService;
import com.gxmailu.ocrCloudPlatform.vo.OcrResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
......@@ -497,7 +496,7 @@ public class RetransmissionService {
}
public OcrResult fullTextRecognition(String fileId, MultipartFile file, HttpServletRequest request) {
public OcrResult fullTextRecognition(String code, String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId);
String tempSaveDir = tempDir + File.separator + IdUtil.fastSimpleUUID() + "_" + System.currentTimeMillis();
......@@ -529,7 +528,7 @@ public class RetransmissionService {
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
try {
res = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ft/1001")
res = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ft/" + code)
.headerMap(getHeaderMap(request), true)
.form(paramMap)
.setConnectionTimeout(10 * 1000)
......@@ -567,7 +566,7 @@ public class RetransmissionService {
}
}
public OcrResult fullTextRecognitionV2(String fileId, MultipartFile file, HttpServletRequest request) {
public OcrResult fullTextRecognitionV2(String code, String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId);
String tempSaveDir = tempDir + File.separator + IdUtil.fastSimpleUUID() + "_" + System.currentTimeMillis();
......@@ -600,7 +599,7 @@ public class RetransmissionService {
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
try {
res = HttpRequest.post(ocrApi + "/ofs/api/sync/v2/1001")
res = HttpRequest.post(ocrApi + "/ofs/api/sync/v2/" + code)
.headerMap(getHeaderMap(request), true)
.form(paramMap)
.setConnectionTimeout(10 * 1000)
......
......@@ -76,7 +76,7 @@ public class ServerInfoServiceImpl implements ServerInfoService {
return Result.serverError("查询分页失败", e.getMessage());
}
return Result.error("未找到相关数据");
return new Result(true, Result.SUCCESS, "未找到相关数据", 0L, null);
}
@Override
......
......@@ -148,4 +148,22 @@
create_date_time = #{createDateTime,jdbcType=TIMESTAMP}
where user_message_id = #{userMessageId,jdbcType=INTEGER}
</update>
<select id="selectUserMessage" resultType="com.gxmailu.ocrCloudPlatform.excel.model.UserMessageModel">
SELECT
m.title,
m.body,
m.pub_date,
m.promulgator,
um.read
FROM
`message` m
LEFT JOIN user_message um ON m.message_id = um.message_id
<where>
<if test="username != null and username != ''">
um.username = #{username}
</if>
</where>
ORDER BY create_date_time DESC
</select>
</mapper>
\ No newline at end of file
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