Commit 15a188ae by HlQ

feat: 添加设备导出功能以及支持按合同编号查询设备

1 parent f06bbe17
package vion.controller; package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.watermark.Watermark;
import com.github.liaochong.myexcel.utils.AttachmentV2ExportUtil;
import com.github.liaochong.myexcel.utils.WatermarkUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.Workbook;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import vion.dto.DeviceDTO; import vion.dto.DeviceDTO;
import vion.service.IDeviceService; import vion.service.IDeviceService;
import vion.vo.DeviceVO; import vion.vo.DeviceVO;
import vion.vo.UserVO;
import java.awt.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
...@@ -52,4 +65,23 @@ public class DeviceController { ...@@ -52,4 +65,23 @@ public class DeviceController {
return deviceService.circulateBatch(dtoList); return deviceService.circulateBatch(dtoList);
} }
@GetMapping("/out/export")
@SaCheckPermission(value = "device:out:export", orRole = "admin")
public void deviceExport(DeviceDTO dto, HttpServletResponse response) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
dto.setPageSize(30000);
Page<DeviceVO> voPage = deviceService.list(dto);
try (DefaultExcelBuilder<DeviceVO> defaultExcelBuilder = DefaultExcelBuilder.of(DeviceVO.class)) {
Workbook workbook = defaultExcelBuilder.build(voPage.getRecords());
// 水印添加指定字体,并在服务器上安装 SimSun 字体,解决中文字体变成方块的问题
Watermark watermark = new Watermark();
watermark.setText(user.getUsername() + "-" + user.getPhone());
watermark.setFont(new Font("SimSun", Font.PLAIN, 16));
WatermarkUtil.addWatermark(workbook, watermark);
AttachmentV2ExportUtil.export(workbook, StrUtil.format("设备列表_{}", TimeUtil.formatNormal(LocalDateTime.now())), response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }
package vion.vo; package vion.vo;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;
import com.github.liaochong.myexcel.core.annotation.Prompt;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import vion.model.DeviceLog; import vion.model.DeviceLog;
...@@ -10,59 +13,74 @@ import java.util.List; ...@@ -10,59 +13,74 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
@ExcelModel(sheetName = "设备列表", includeAllField = false)
public class DeviceVO { public class DeviceVO {
private Long id; private Long id;
/** /**
* 合同编号 * 合同编号
*/ */
@ExcelColumn(order = 0, title = "合同编号")
private String contractNo; private String contractNo;
/** /**
* 合同名称 * 合同名称
*/ */
@ExcelColumn(order = 1, title = "合同名称")
private String contractName; private String contractName;
/** /**
* 设备序列号 * 设备序列号
*/ */
@ExcelColumn(order = 2, title = "设备序列号")
private String serialNum; private String serialNum;
/** /**
* 设备mac地址 * 设备mac地址
*/ */
@ExcelColumn(order = 3, title = "mac")
private String mac; private String mac;
/** /**
* 设备id * 设备id
*/ */
@ExcelColumn(order = 4, title = "设备ID")
private String deviceId; private String deviceId;
/** /**
* 物料编号 * 物料编号
*/ */
@ExcelColumn(order = 5, title = "物料编号")
private String materialNum; private String materialNum;
/** /**
* 生产部门 * 生产部门
*/ */
@ExcelColumn(order = 6, title = "生产部门")
private String prodSector; private String prodSector;
/** /**
* 状态:入库1、出库2、维修3、借测4、废弃5 * 状态:入库1、出库2、维修3、借测4、废弃5
*/ */
@ExcelColumn(order = 7, title = "状态", mapping = "1:入库,2:出库,3:维修,4:借测,5:废弃")
private Integer status; private Integer status;
/** /**
* 入库日期,当状态为2时,该字段表示出库日期 * 入库日期,当状态为2时,该字段表示出库日期
*/ */
@ExcelColumn(order = 8, title = "日期", format = "yyyy-MM-dd", prompt = @Prompt(text = " 入库日期,当状态为出库时,该字段表示出库日期"), style = {"title" +
"->color" +
":red"})
private LocalDate recDate; private LocalDate recDate;
/** /**
* 备注 * 备注
*/ */
@ExcelColumn(order = 9, title = "备注")
private String remark; private String remark;
@ExcelColumn(order = 10, title = "创建时间")
private LocalDateTime createTime; private LocalDateTime createTime;
@ExcelColumn(order = 11, title = "更新时间")
private LocalDateTime updateTime; private LocalDateTime updateTime;
private List<DeviceLog> logList; private List<DeviceLog> logList;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!