导入:
前端
java
<el-form-item>
<el-upload
class="upload-demo"
ref="upload"
action="http://172.25.26.102:8180/base/importDeviceInfo"
:on-preview="handlePreview"
:on-success="uploadFileSuccess"
:on-remove="handleRemove"
:before-remove="beforeRemove"
multiple
:limit="1"
:on-exceed="handleExceed"
:file-list="fileList">
<el-button type="primary">批量上传</el-button>
</el-upload>
</el-form-item>
uploadFileSuccess(res) {
console.log(res);
this.$refs.upload.clearFiles();
if(res=='上传失败,设备资产编码不能重复!'){
this.$message({
showClose: true,
message: '上传失败,设备资产编码不能重复!',
type: 'error'
});
}else if(res=='上传失败,不能有空值!'){
this.$message({
showClose: true,
message: '上传失败,不能有空值!',
type: 'error'
});
}else{
this.$message({
showClose: true,
message: '上传成功!',
type: 'success'
});
}
后端:
java
//导入设备信息
@ResponseBody
@PostMapping("/importDeviceInfo")
public void importDeviceInfo(@RequestParam("file") MultipartFile file) throws Exception {
baseService.importDeviceInfo(file);
}
@Autowired
private DeviceExcelVerify deviceExcelVerify;
// 导入设备信息
public void importDeviceInfo(MultipartFile file) throws Exception {
List<DeviceBase2> objects = new ArrayList<>();
EasyExcel.read(file.getInputStream(),DeviceBase2.class,new PageReadListener<DeviceBase2>(
deviceList->{
for (DeviceBase2 deviceBase2 : deviceList) {
objects.add(deviceBase2);
}
}
)).excelType(ExcelTypeEnum.XLSX).sheet().doRead();
for (DeviceBase2 deviceBase : objects) {
String now = LocalDate.now().toString();
deviceBase.setDevice_state_time(now);
String apply_time = deviceBase.getApply_time();
String replace = apply_time.replace("/", "-");
deviceBase.setApply_time(replace);
String come_device_time = deviceBase.getCome_device_time();
String replace1 = come_device_time.replace("/", "-");
deviceBase.setCome_device_time(replace1);
}
deviceBaseMapper.batchInsearchDevice(objects);}
导出:
前端:
java
<el-form-item>
<el-button type="primary" @click="m4">导出数据</el-button>
</el-form-item>
async m4(){
let link = document.createElement('a');
link.style.display = 'none'
const resp = await axios.post('http://172.25.26.102:8180/base/export',{
belong_park: this.exportCondition.belong_park,
belong_workshop: this.exportCondition.belong_workshop,
belong_unit: this.exportCondition.belong_unit,
device_property_code: this.exportCondition.device_property_code,
contract_code: this.exportCondition.contract_code,
device_provide_factory: this.exportCondition.device_provide_factory,
device_name: this.exportCondition.device_name,
deviceBlock: this.exportCondition.deviceBlock,
},{
responseType: 'arraybuffer',
headers: {
'token': localStorage.getItem('token')
}
})
let blob = new Blob([resp.data], {
type: "application/vnd.ms-excel"
});
let url = window.URL.createObjectURL(blob); // 3.创建一个临时的url指向blob对象
// 4.创建url之后可以模拟对此文件对象的一系列操作,例如:预览、下载
let a = document.createElement("a");
a.href = url;
a.download = "设备资产信息表.xls";
a.click();
// 5.释放这个临时的对象url
window.URL.revokeObjectURL(url);
console.log(resp)
<!-- saveAs(resp.data,'设备台账记录.xlsx')-->
},
后端:
java
//导出设备信息
@ResponseBody
@PostMapping("/export")
public void export(@RequestBody GetDeviceInfoDto getDeviceInfoDto, HttpServletResponse response, ServletRequest servletRequest,@RequestHeader("token") String token){
HttpServletRequest req = (HttpServletRequest) servletRequest;
String token1 = req.getHeader("token");
baseService.export(getDeviceInfoDto,response);
}
//导出设备信息
@Override
public void export(GetDeviceInfoDto getDeviceInfoDto,HttpServletResponse response) {
String belong_park = getDeviceInfoDto.getBelong_park();
String device_property_code = getDeviceInfoDto.getDevice_property_code();
String contract_code = getDeviceInfoDto.getContract_code();
String device_provide_factory = getDeviceInfoDto.getDevice_provide_factory();
String device_name = getDeviceInfoDto.getDevice_name();
//====================
String belong_workshop = getDeviceInfoDto.getBelong_workshop();
String belong_unit = getDeviceInfoDto.getBelong_unit();
String deviceBlock = getDeviceInfoDto.getDeviceBlock();
List<DeviceAllInfo> list = deviceBaseMapper.export2(belong_park,deviceBlock,belong_workshop,belong_unit,device_property_code,contract_code,device_provide_factory,device_name);
ArrayList<DeviceBase> objects = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
DeviceBase deviceBase = new DeviceBase();
deviceBase.setBelong_park(list.get(i).getBelong_park());
deviceBase.setDeviceBlock(list.get(i).getDeviceBlock());
deviceBase.setBelong_unit(list.get(i).getBelong_unit());
deviceBase.setBelong_workshop(list.get(i).getBelong_workshop());
deviceBase.setDevice_name(list.get(i).getDevice_name());
deviceBase.setDevice_type(list.get(i).getDevice_type());
deviceBase.setDevice_number(list.get(i).getDevice_number());
deviceBase.setDevice_number_unit(list.get(i).getDevice_number_unit());
deviceBase.setDevice_property_code(list.get(i).getDevice_property_code());
deviceBase.setOut_factory_code(list.get(i).getOut_factory_code());
deviceBase.setApply_people(list.get(i).getApply_people());
deviceBase.setApply_time(list.get(i).getApply_time());
deviceBase.setContract_code(list.get(i).getContract_code());
deviceBase.setDevice_provide_factory(list.get(i).getDevice_provide_factory());
deviceBase.setCome_device_time(list.get(i).getCome_device_time());
deviceBase.setDevice_sort(list.get(i).getDevice_sort());
deviceBase.setDevice_money(list.get(i).getDevice_money());
deviceBase.setDevice_state(list.get(i).getDevice_state());
String device_state_time1 = list.get(i).getDevice_state_time();
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(device_state_time1, dateTimeFormatter1);
long between1 = ChronoUnit.DAYS.between(startDate, LocalDate.now());
if (list.get(i).getDevice_state()!=null&&list.get(i).getDevice_state()!=""){
String device_state = list.get(i).getDevice_state();
deviceBase.setDevice_state_time(device_state+"时长:"+between1+"天");
}else {
deviceBase.setDevice_state_time("无状态");
}
deviceBase.setNotes(list.get(i).getNotes());
//开箱记录
ArrayList<DeviceOpenBoxCheck> objects1 = new ArrayList<>();
if (list.get(i).getOpen_box_time()!=null){
String[] split = list.get(i).getOpen_box_time().split("mzd\\$");
String[] split1 = list.get(i).getOpen_box_state().split("mzd\\$");
for (int j = 0; j < split.length; j++) {
DeviceOpenBoxCheck deviceOpenBoxCheck = new DeviceOpenBoxCheck();
deviceOpenBoxCheck.setOpen_box_time(split[j]);
deviceOpenBoxCheck.setOpen_box_state(split1[j]);
objects1.add(deviceOpenBoxCheck);
}
}
//启用检验记录
ArrayList<DeviceUseCheck> objects2 = new ArrayList<>();
if (list.get(i).getUse_time()!=null){
String[] split = list.get(i).getUse_time().split("mzd\\$");
String[] split1 = list.get(i).getUse_state().split("mzd\\$");
for (int j = 0; j < split.length; j++) {
DeviceUseCheck deviceUseCheck = new DeviceUseCheck();
deviceUseCheck.setUse_time(split[j]);
deviceUseCheck.setUse_state(split1[j]);
objects2.add(deviceUseCheck);
}
}
//验收记录
ArrayList<DeviceCheckAcceptRecord> objects3 = new ArrayList<>();
if (list.get(i).getCheck_accept_time()!=null&&list.get(i).getCheck_accept_advice()!=null){
String[] split = list.get(i).getCheck_accept_result().split("mzd\\$");
String[] split1 = list.get(i).getCheck_accept_advice().split("mzd\\$");
String[] split2 = list.get(i).getCheck_accept_time().split("mzd\\$");
for (int j = 0; j < split2.length; j++) {
DeviceCheckAcceptRecord deviceCheckAcceptRecord = new DeviceCheckAcceptRecord();
deviceCheckAcceptRecord.setCheck_accept_result(split[j]);
deviceCheckAcceptRecord.setCheck_accept_advice(split1[j]);
deviceCheckAcceptRecord.setCheck_accept_time(split2[j]);
objects3.add(deviceCheckAcceptRecord);
}
}
//转入出记录
ArrayList<DeviceOutAcceptRecord> objects4 = new ArrayList<>();
if (list.get(i).getOut_accept_time()!=null){
String[] split5 = list.get(i).getType().split("mzd\\$");
String[] split = list.get(i).getOut_park().split("mzd\\$");
String[] split1 = list.get(i).getOut_unit().split("mzd\\$");
String[] split3 = list.get(i).getAccept_park().split("mzd\\$");
String[] split4 = list.get(i).getAccept_unit().split("mzd\\$");
String[] split2 = list.get(i).getOut_accept_time().split("mzd\\$");
for (int j = 0; j < split2.length; j++) {
DeviceOutAcceptRecord deviceOutAcceptRecord = new DeviceOutAcceptRecord();
deviceOutAcceptRecord.setType(split5[j]);
deviceOutAcceptRecord.setOut_park(split[j]);
deviceOutAcceptRecord.setOut_unit(split1[j]);
deviceOutAcceptRecord.setAccept_park(split3[j]);
deviceOutAcceptRecord.setAccept_unit(split4[j]);
deviceOutAcceptRecord.setOut_accept_time(split2[j]);
objects4.add(deviceOutAcceptRecord);
}
}
//设备质保信息
ArrayList<DeviceQualityInfo> objects5 = new ArrayList<>();
if (list.get(i).getQuality_time()!=null){
String[] split = list.get(i).getQuality_time().split("mzd\\$");
String[] split1 = list.get(i).getQuality_state().split("mzd\\$");
String[] split2 = list.get(i).getQuality_advice().split("mzd\\$");
for (int j = 0; j < split.length; j++) {
DeviceQualityInfo deviceQualityInfo = new DeviceQualityInfo();
deviceQualityInfo.setQuality_time(split[j]);
deviceQualityInfo.setQuality_state(split1[j]);
deviceQualityInfo.setQuality_advice(split2[j]);
objects5.add(deviceQualityInfo);
}
}
//设备改造记录
ArrayList<DeviceChangeRecord> objects6 = new ArrayList<>();
if (list.get(i).getChange_time()!=null){
String[] split = list.get(i).getChange_content().split("mzd\\$");
String[] split1 = list.get(i).getChange_time().split("mzd\\$");
for (int j = 0; j < split1.length; j++) {
DeviceChangeRecord deviceChangeRecord = new DeviceChangeRecord();
deviceChangeRecord.setChange_content(split[j]);
deviceChangeRecord.setChange_time(split1[j]);
objects6.add(deviceChangeRecord);
}
}
//设备处置记录
ArrayList<DeviceDealRecord> objects7 = new ArrayList<>();
if (list.get(i).getDeal_time()!=null){
String[] split = list.get(i).getDeal_type().split("mzd\\$");
String[] split1 = list.get(i).getDeal_result().split("mzd\\$");
String[] split2 = list.get(i).getDeal_time().split("mzd\\$");
for (int j = 0; j < split2.length; j++) {
DeviceDealRecord deviceDealRecord = new DeviceDealRecord();
deviceDealRecord.setDeal_type(split[j]);
deviceDealRecord.setDeal_result(split1[j]);
deviceDealRecord.setDeal_time(split2[j]);
objects7.add(deviceDealRecord);
}
}
//设备借用记录
ArrayList<DeviceBorrowRecord> objects8 = new ArrayList<>();
if (list.get(i).getBorrow_time()!=null){
String[] split = list.get(i).getBorrow_time().split("mzd\\$");
String[] split1 = list.get(i).getBorrow_park().split("mzd\\$");
String[] split2 = new String[0];
try {
split2 = list.get(i).getBorrow_unit().split("mzd\\$");
} catch (Exception e) {
e.printStackTrace();
}
String[] split3 = list.get(i).getReturn_time().split("mzd\\$");
for (int j = 0; j < split3.length; j++) {
DeviceBorrowRecord deviceBorrowRecord = new DeviceBorrowRecord();
deviceBorrowRecord.setBorrow_time(split[j]);
deviceBorrowRecord.setBorrow_park(split1[j]);
deviceBorrowRecord.setBorrow_unit(split2[j]);
deviceBorrowRecord.setReturn_time(split3[j]);
objects8.add(deviceBorrowRecord);
}
}
deviceBase.setDeviceOpenBoxChecks(objects1);
deviceBase.setDeviceUseChecks(objects2);
deviceBase.setDeviceCheckAcceptRecords(objects3);
deviceBase.setDeviceOutAcceptRecords(objects4);
deviceBase.setDeviceQualityInfos(objects5);
deviceBase.setDeviceChangeRecords(objects6);
deviceBase.setDeviceDealRecords(objects7);
deviceBase.setDeviceBorrowRecords(objects8);
objects.add(deviceBase);
}
MyExcelUtils.exportExcel(objects,"设备信息","设备信息",DeviceBase.class,"设备资产信息表.xlsx",response);}
模板下载:
前端:
java
<el-form-item>
<el-button type="primary" @click="m8">模版下载</el-button>
</el-form-item>
async m8(){
const resp = await axios.post('http://172.25.26.102:8180/base/downloadTemplate',{},
{
headers: {
'token': localStorage.getItem('token')
},
responseType: 'blob'
})
saveAs(resp.data,'台账导入模版.xlsx')
},
后端:
java
//模版下载
@ResponseBody
@PostMapping("/downloadTemplate")
public void downloadTemplate(HttpServletResponse response) throws IOException {
InputStream fileInputStream = this.getClass().getClassLoader().getResourceAsStream("file/台账导入模板.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
fileInputStream.close();
outputStream.close();
workbook.close();
}
tabs页面:
前端
java
<el-form-item label="设备开箱清单" :label-width="formLabelWidth">
<el-upload
class="upload-demo"
ref="upload"
action=""
multiple
:http-request="insertM1"
:on-preview="handlePreview"
:on-remove="handleRemove"
:file-list="fileList1"
:auto-upload="false"
:clear-files="true"
:limit="1"
>
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
<div slot="tip" class="el-upload__tip">文件不超过10MB</div>
</el-upload>
</el-form-item>
insertm1(){
if(this.$refs.upload.uploadFiles.length==1){
this.$refs.upload.submit();
}
else{
console.log('222');
let fd = new FormData();
fd.append('open_box_time',this.box.boxTime)
fd.append('open_box_state',this.value1)
fd.append('device_id',this.param)
axios.post('http://172.25.19.57:8080/tabs/insertBox',fd,
{
headers: {
'token': this.token
}
})
this.$message({
showClose: true,
message: '添加成功!',
type: 'success'
});
<!-- axios.post(-->
<!-- 'http://172.25.19.57:8080/tabs/insertBox',-->
<!-- {-->
<!-- open_box_time: this.box.boxTime,-->
<!-- open_box_state: this.value1,-->
<!--<!– device_open_box_list: this.box.boxList,–>-->
<!-- device_id: this.param-->
<!-- }-->
<!-- )-->
this.m1();
this.box.boxTime = '';
this.value1 = '';
this.box.boxList = '';
this.$refs.upload.clearFiles();
}
},
insertM1(file){
console.log('222');
let fd = new FormData();
fd.append('open_box_time',this.box.boxTime)
fd.append('open_box_state',this.value1)
fd.append('device_id',this.param)
fd.append('file',file.file)
axios.post('http://172.25.19.57:8080/tabs/insertBox',fd,
{
headers: {
'token': this.token
}
})
this.$message({
showClose: true,
message: '添加成功!',
type: 'success'
});
<!-- axios.post(-->
<!-- 'http://172.25.19.57:8080/tabs/insertBox',-->
<!-- {-->
<!-- open_box_time: this.box.boxTime,-->
<!-- open_box_state: this.value1,-->
<!--<!– device_open_box_list: this.box.boxList,–>-->
<!-- device_id: this.param-->
<!-- }-->
<!-- )-->
this.m1();
this.box.boxTime = '';
this.value1 = '';
this.box.boxList = '';
this.$refs.upload.clearFiles();
},
后端
java
//添加设备质保信息
@ResponseBody
@PostMapping("/insertQuality")
public void insertQuality(DeviceQualityInfo deviceQualityInfo,MultipartFile file) throws IOException {
deviceTabsService.insertQuality(deviceQualityInfo,file);
}
//添加设备质保信息
@Override
public void insertQuality(DeviceQualityInfo deviceQualityInfo,MultipartFile file) throws IOException {
String originalFilename = file.getOriginalFilename();
// String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
String s = UUID.randomUUID().toString();
String newName = s + originalFilename;
String substring = System.getProperty("user.dir")+"/uploadFile/";
file.transferTo(new File(substring+newName));
deviceQualityInfo.setQuality_reference_file(substring+newName);
// file.transferTo(new File("E:\\file\\"+newName));
// deviceQualityInfo.setQuality_reference_file("E:\\file\\"+newName);
deviceTabsMapper.insertQuality(deviceQualityInfo);
}
附件下载(就是文件下载,tab页面的功能,跟模板下载一样)
前端
java
<template slot-scope="scope">
<!-- <span style="margin-left: 10px">{{ scope.row.device_open_box_list }}</span>-->
<el-button type="primary" icon="el-icon-download" @click="m161(scope.$index, scope.row)">附件下载</el-button>
</template>
async m161(index,row){
console.log(row);
const resp = await axios.post('http://172.25.19.57:8080/tabs/download',{
filename: row.outsource_repair_file
},{
responseType: 'blob',
headers: {
'token': this.token
}
})
let fileOriginalName = row.outsource_repair_file;
let substring1 = fileOriginalName.substring(44);
console.log(substring1)
saveAs(resp.data,substring1)
console.log(row)
},
后端
java
@PostMapping("/download")
public void download(@RequestBody FileName fileNames, HttpServletResponse response) throws IOException {
// E:\file\3a6ffee0-1213-4a99-b4b5-ba36e8f2ce01.txt
//E:\file\a982666c-fafa-4310-a931-de6c83e6f5ba.txt
//E:\\file\\a982666c-fafa-4310-a931-de6c83e6f5ba.txt
// String fileOrigin = "E:\\测试\\集团安委办(202410)TB-001关于珠海园区10.12储能柜装配事故的监督通报.pdf";
String fileOrigins = fileNames.getFilename();
//String fileOrigin = fileOrigins.replace("\\", "\\\\");
//String fileName = new File(fileOrigins).getName();
FileInputStream in = new FileInputStream(fileOrigins);
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileOrigins, "UTF-8") + "\"");
response.setContentType("application/octet-stream");
//response.setHeader("Content-Disposition","attachment;filename=" + fileOrigin);
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
byte[] b = new byte[1024];
int len;
while ((len=in.read(b)) != -1){
out.write(b,0,len);
}
out.close();
in.close();
}