Commit a01a09c3 authored by 鲁鸿波's avatar 鲁鸿波

历史状态字段调整及漏缆监测历史状态的导出

parent 910b156e
package com.hongxinhui.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.hongxinhui.entity.HmsLeakycableMonitorStatus;
import com.hongxinhui.entity.excel.HmsLeakycableMonitorStatusPo;
import com.hongxinhui.mapper.HmsLeakycableMonitorStatusMapper;
import com.hongxinhui.service.HmsLeakycableMonitorStatusService;
import lombok.extern.slf4j.Slf4j;
import com.hongxinhui.param.HmsLeakycableMonitorStatusPageParam;
......@@ -13,17 +20,29 @@ import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 漏缆监测历史状态 控制器
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
@Slf4j
@RestController
......@@ -32,9 +51,14 @@ import org.springframework.web.bind.annotation.*;
@Api(value = "漏缆监测历史状态API", tags = {"漏缆监测历史状态"})
public class HmsLeakycableMonitorStatusController extends BaseController {
private Logger logger = LoggerFactory.getLogger(HmsLeakycableMonitorStatusController.class);
@Autowired
private HmsLeakycableMonitorStatusService hmsLeakycableMonitorStatusService;
@Autowired
private HmsLeakycableMonitorStatusMapper hmsLeakycableMonitorStatusMapper;
/**
* 添加漏缆监测历史状态
*/
......@@ -60,11 +84,11 @@ public class HmsLeakycableMonitorStatusController extends BaseController {
/**
* 删除漏缆监测历史状态
*/
@PostMapping("/delete/{id}")
@PostMapping("/delete")
@OperationLog(name = "删除漏缆监测历史状态", type = OperationLogType.DELETE)
@ApiOperation(value = "删除漏缆监测历史状态", response = ApiResult.class)
public ApiResult<Boolean> deleteHmsLeakycableMonitorStatus(@PathVariable("id") Long id) throws Exception {
boolean flag = hmsLeakycableMonitorStatusService.deleteHmsLeakycableMonitorStatus(id);
public ApiResult<Boolean> deleteHmsLeakycableMonitorStatus(@RequestBody List<Long> ids) throws Exception {
boolean flag = hmsLeakycableMonitorStatusService.deleteHmsLeakycableMonitorStatus(ids);
return ApiResult.result(flag);
}
......@@ -90,5 +114,12 @@ public class HmsLeakycableMonitorStatusController extends BaseController {
return ApiResult.ok(paging);
}
@PostMapping("/excelImport")
@OperationLog(name = "漏缆监测历史状态导出", type = OperationLogType.excel_import)
@ApiOperation(value = "漏缆监测历史状态导出", response = HmsLeakycableMonitorStatusPo.class)
public void excelImport(@RequestBody List<Long> ids,HttpServletResponse response) throws IOException {
hmsLeakycableMonitorStatusService.importExcel(ids,response);
}
}
......@@ -21,7 +21,7 @@ import io.geekidea.springbootplus.framework.core.validator.groups.Update;
* 漏缆监测维护历史
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
@Data
@Accessors(chain = true)
......@@ -53,8 +53,14 @@ public class HmsLeakycableMaintain extends BaseEntity {
@ApiModelProperty("告警级别(10: 一般, 20: 重要, 30: 紧急)")
private Integer level;
@ApiModelProperty("告警信息")
private String content;
@ApiModelProperty("告警信息(红)")
private String contentRed;
@ApiModelProperty("告警信息(绿)")
private String contentGreen;
@ApiModelProperty("告警信息(黑)")
private String contentBlack;
@ApiModelProperty("告警维修时间")
@TableField("maintainTime")
......@@ -80,7 +86,9 @@ public class HmsLeakycableMaintain extends BaseEntity {
alarmName("alarmName", "告警对象"),
alarmId("alarmId", "告警对象id"),
level("level", "告警级别(10: 一般, 20: 重要, 30: 紧急)"),
content("content", "告警信息"),
contentRed("contentRed", "告警信息(红)"),
contentGreen("contentGreen", "告警信息(绿)"),
contentBlack("contentBlack", "告警信息(黑)"),
maintainTime("maintainTime", "告警维修时间"),
deleted("deleted", "是否删除(0: 未删除, 1: 已删除)"),
deletedBy("deletedBy", "删除者"),
......@@ -109,6 +117,11 @@ public class HmsLeakycableMaintain extends BaseEntity {
return null;
}
@Override
public String getDesc() {
return null;
}
}
}
......@@ -21,7 +21,7 @@ import io.geekidea.springbootplus.framework.core.validator.groups.Update;
* 漏缆监测历史状态
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
@Data
@Accessors(chain = true)
......@@ -50,8 +50,14 @@ public class HmsLeakycableMonitorStatus extends BaseEntity {
@TableField("alarmId")
private Long alarmId;
@ApiModelProperty("告警信息")
private String content;
@ApiModelProperty("告警信息(红)")
private String contentRed;
@ApiModelProperty("告警信息(绿)")
private String contentGreen;
@ApiModelProperty("告警信息(黑)")
private String contentBlack;
@ApiModelProperty("上传时间")
@TableField("uploadTime")
......@@ -76,7 +82,9 @@ public class HmsLeakycableMonitorStatus extends BaseEntity {
bsId("bsId", "基站id"),
alarmName("alarmName", "告警对象"),
alarmId("alarmId", "告警对象id"),
content("content", "告警信息"),
contentRed("contentRed", "告警信息(红)"),
contentGreen("contentGreen", "告警信息(绿)"),
contentBlack("contentBlack", "告警信息(黑)"),
uploadTime("uploadTime", "上传时间"),
deleted("deleted", "是否删除(0: 未删除, 1: 已删除)"),
deletedBy("deletedBy", "删除者"),
......
package com.hongxinhui.service;
import com.hongxinhui.entity.HmsLeakycableMonitorStatus;
import com.hongxinhui.entity.excel.HmsLeakycableMonitorStatusPo;
import com.hongxinhui.param.HmsLeakycableMonitorStatusPageParam;
import io.geekidea.springbootplus.framework.common.service.BaseService;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* 漏缆监测历史状态 服务类
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
public interface HmsLeakycableMonitorStatusService extends BaseService<HmsLeakycableMonitorStatus> {
......@@ -38,7 +43,7 @@ public interface HmsLeakycableMonitorStatusService extends BaseService<HmsLeakyc
* @return
* @throws Exception
*/
boolean deleteHmsLeakycableMonitorStatus(Long id) throws Exception;
boolean deleteHmsLeakycableMonitorStatus(List<Long> ids) throws Exception;
/**
......@@ -50,4 +55,7 @@ public interface HmsLeakycableMonitorStatusService extends BaseService<HmsLeakyc
*/
Paging<HmsLeakycableMonitorStatus> getHmsLeakycableMonitorStatusPageList(HmsLeakycableMonitorStatusPageParam hmsLeakycableMonitorStatusPageParam) throws Exception;
public List<HmsLeakycableMonitorStatusPo> HmsLeakycableMonitorStatusToPo(List<HmsLeakycableMonitorStatus> hmsLeakycableMonitorStatuses);
public void importExcel(List<Long> ids,HttpServletResponse response) throws IOException;
}
......@@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
* 漏缆监测维护历史 服务实现类
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
@Slf4j
@Service
......@@ -49,7 +49,7 @@ public class HmsLeakycableMaintainServiceImpl extends BaseServiceImpl<HmsLeakyca
@Override
public Paging<HmsLeakycableMaintain> getHmsLeakycableMaintainPageList(HmsLeakycableMaintainPageParam hmsLeakycableMaintainPageParam) throws Exception {
Page<HmsLeakycableMaintain> page = new PageInfo<>(hmsLeakycableMaintainPageParam, OrderItem.desc(getLambdaColumn(HmsLeakycableMaintain::getId)));
Page<HmsLeakycableMaintain> page = new PageInfo<>(hmsLeakycableMaintainPageParam, OrderItem.desc(getLambdaColumn(HmsLeakycableMaintain::getMaintainTime)));
LambdaQueryWrapper<HmsLeakycableMaintain> wrapper = new LambdaQueryWrapper<>();
IPage<HmsLeakycableMaintain> iPage = hmsLeakycableMaintainMapper.selectPage(page, wrapper);
return new Paging<HmsLeakycableMaintain>(iPage);
......
package com.hongxinhui.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.hongxinhui.entity.HmsLeakycableMonitorStatus;
import com.hongxinhui.entity.excel.HmsLeakycableMonitorStatusPo;
import com.hongxinhui.enums.CommonEnums;
import com.hongxinhui.mapper.HmsLeakycableMonitorStatusMapper;
import com.hongxinhui.service.HmsLeakycableMonitorStatusService;
import com.hongxinhui.param.HmsLeakycableMonitorStatusPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hongxinhui.utils.CommonAttributeSet;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 漏缆监测历史状态 服务实现类
*
* @author cyz
* @since 2022-02-14
* @since 2022-02-15
*/
@Slf4j
@Service
public class HmsLeakycableMonitorStatusServiceImpl extends BaseServiceImpl<HmsLeakycableMonitorStatusMapper, HmsLeakycableMonitorStatus> implements HmsLeakycableMonitorStatusService {
private Logger logger = LoggerFactory.getLogger(HmsLeakycableMonitorStatusServiceImpl.class);
@Autowired
private HmsLeakycableMonitorStatusMapper hmsLeakycableMonitorStatusMapper;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveHmsLeakycableMonitorStatus(HmsLeakycableMonitorStatus hmsLeakycableMonitorStatus) throws Exception {
//系统为实时系统,上传的信息与前一次上传信息比较,如状态无变化,则不进行历史记录!只有漏缆状态发生改变才进行记录,方便用户数据分析。
//一些公用的属性赋值(删除状态,创建人,创建时间)
CommonAttributeSet commonAttributeSet = new CommonAttributeSet().builderInsert();
BeanUtils.copyProperties(commonAttributeSet,hmsLeakycableMonitorStatus);
return super.save(hmsLeakycableMonitorStatus);
}
......@@ -43,16 +71,79 @@ public class HmsLeakycableMonitorStatusServiceImpl extends BaseServiceImpl<HmsLe
@Transactional(rollbackFor = Exception.class)
@Override
public boolean deleteHmsLeakycableMonitorStatus(Long id) throws Exception {
return super.removeById(id);
public boolean deleteHmsLeakycableMonitorStatus(List<Long> ids) throws Exception {
List<HmsLeakycableMonitorStatus> hmsLeakycableMonitorStatuses = hmsLeakycableMonitorStatusMapper.selectBatchIds(ids);
//一些公用的属性赋值(删除标识,删除人,删除时间)
for(HmsLeakycableMonitorStatus hmsLeakycableMonitorStatuse : hmsLeakycableMonitorStatuses){
BeanUtils.copyProperties(new CommonAttributeSet().builderDeleted(),hmsLeakycableMonitorStatuse);
}
return super.updateBatchById(hmsLeakycableMonitorStatuses);
}
@Override
public Paging<HmsLeakycableMonitorStatus> getHmsLeakycableMonitorStatusPageList(HmsLeakycableMonitorStatusPageParam hmsLeakycableMonitorStatusPageParam) throws Exception {
Page<HmsLeakycableMonitorStatus> page = new PageInfo<>(hmsLeakycableMonitorStatusPageParam, OrderItem.desc(getLambdaColumn(HmsLeakycableMonitorStatus::getId)));
Page<HmsLeakycableMonitorStatus> page = new PageInfo<>(hmsLeakycableMonitorStatusPageParam, OrderItem.desc(getLambdaColumn(HmsLeakycableMonitorStatus::getUploadTime)));
LambdaQueryWrapper<HmsLeakycableMonitorStatus> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(HmsLeakycableMonitorStatus::getDeleted, CommonEnums.DELETED0.getCode());
IPage<HmsLeakycableMonitorStatus> iPage = hmsLeakycableMonitorStatusMapper.selectPage(page, wrapper);
return new Paging<HmsLeakycableMonitorStatus>(iPage);
}
/**
*转换成导出对象
* @param hmsLeakycableMonitorStatuses
* @return
*/
@Override
public List<HmsLeakycableMonitorStatusPo> HmsLeakycableMonitorStatusToPo(List<HmsLeakycableMonitorStatus> hmsLeakycableMonitorStatuses){
List<HmsLeakycableMonitorStatusPo> hmsLeakycableMonitorStatusPos = new ArrayList<>();
for(HmsLeakycableMonitorStatus hmsLeakycableMonitorStatusPo : hmsLeakycableMonitorStatuses){
hmsLeakycableMonitorStatusPos.add(new HmsLeakycableMonitorStatusPo(
hmsLeakycableMonitorStatusPo.getBsName(),
hmsLeakycableMonitorStatusPo.getAlarmName(),
hmsLeakycableMonitorStatusPo.getContentRed(),
hmsLeakycableMonitorStatusPo.getContentGreen(),
hmsLeakycableMonitorStatusPo.getContentBlack(),
hmsLeakycableMonitorStatusPo.getUploadTime()));
}
return hmsLeakycableMonitorStatusPos;
}
@Override
public void importExcel(List<Long> ids, HttpServletResponse response) throws IOException {
try {
List<HmsLeakycableMonitorStatus> hmsLeakycableMonitorStatuses = hmsLeakycableMonitorStatusMapper.selectBatchIds(ids);
String templateFileName = "config/src/main/resources/static/excelTemplate/test.xlsx";
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(templateFileName).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
// 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。
// forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用
// 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
// 如果数据量大 list不是最后一行 参照下一个
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
excelWriter.fill(HmsLeakycableMonitorStatusToPo(hmsLeakycableMonitorStatuses), fillConfig, writeSheet);
/*Map<String, Object> map = new HashMap<String, Object>();
LocalDate now = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月份");
String date = now.format(formatter);
map.put("date", date);
map.put("month", "10");//自定义模板填充
excelWriter.fill(map, writeSheet);*/
// 这里URLEncoder.encode可以防止中文乱码
String fileName = URLEncoder.encode("漏缆监测历史状态表", "UTF-8").replaceAll("\\+", "%20");
response = new CommonAttributeSet().builderResponseSuccess(response,fileName);
excelWriter.finish();
} catch (Exception e) {
log.error("写入失败", e);
response = new CommonAttributeSet().builderResponseFail(response);
Map<String, String> map = new HashMap<String, String>();
map.put("status", "failure");
map.put("message", "下载文件失败" + e.getMessage());
response.getWriter().println(JSON.toJSONString(map));
}
}
}
package com.hongxinhui.utils;
import com.alibaba.fastjson.JSON;
import com.hongxinhui.entity.User;
import com.hongxinhui.enums.CommonEnums;
import com.hongxinhui.service.impl.HmsLeakycableMonitorStatusServiceImpl;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.geekidea.springbootplus.framework.util.LoginUtil;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName CommonAttributeSet: 公用属性赋值
......@@ -18,6 +26,8 @@ import java.util.Date;
@Data
public class CommonAttributeSet extends BaseEntity {
private Logger logger = LoggerFactory.getLogger(CommonAttributeSet.class);
private Integer deleted;
private String deletedBy;
private Date deletedTime;
......@@ -88,4 +98,27 @@ public class CommonAttributeSet extends BaseEntity {
return commonAttributeSet;
}
public HttpServletResponse builderResponseSuccess(HttpServletResponse response,String fileName){
try{
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
}catch (Exception e) {
logger.error(e.getMessage(), e);
}
return response;
}
public HttpServletResponse builderResponseFail(HttpServletResponse response){
try{
// 重置response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
}catch (Exception e) {
logger.error(e.getMessage(), e);
}
return response;
}
}
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