仪器序列号导出模块开发-批量导入

master
elliott 2 years ago
parent 8ef1d5daae
commit 72931705d2

@ -0,0 +1,61 @@
package com.flossom.common.core.domain.req;
import com.flossom.common.core.annotation.Excel;
import com.flossom.common.core.annotation.Excel.Type;
import java.util.Date;
public class WxInstrumentSerialImportVm {
/**
* id
*/
@Excel(name = "仪器id",type = Type.IMPORT)
private Long instrumentId;
/** 来源 */
@Excel(name = "来源",type = Type.IMPORT)
private String source;
/** 序列号 */
@Excel(name = "序列号",type = Type.IMPORT)
private String serial;
/** 序列号有效状态1有效0无效 */
@Excel(name = "有效状态",type = Type.IMPORT)
private String validStatus;
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getSerial() {
return serial;
}
public void setSerial(String serial) {
this.serial = serial;
}
public String getValidStatus() {
return validStatus;
}
public void setValidStatus(String validStatus) {
this.validStatus = validStatus;
}
public Long getInstrumentId() {
return instrumentId;
}
public void setInstrumentId(Long instrumentId) {
this.instrumentId = instrumentId;
}
}

@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectWxInstrumentSerialVo">
select id, instrument_id, instrument_name, serial, binding_status, valid_status, status, create_by, create_time, remark from wx_instrument_serial
select id, source,instrument_id, instrument_name, serial, binding_status, valid_status, status, create_by, create_time, remark from wx_instrument_serial
</sql>
<select id="selectWxInstrumentSerialList" parameterType="WxInstrumentSerial" resultMap="WxInstrumentSerialResult">

@ -4,9 +4,11 @@ import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.flossom.common.core.domain.entity.SysUser;
import com.flossom.common.core.domain.entity.WxInstrumentSerial;
import com.flossom.common.core.domain.entity.WxUserInstrument;
import com.flossom.common.core.domain.req.WxInstrumentSerialExportVm;
import com.flossom.common.core.domain.req.WxInstrumentSerialImportVm;
import com.flossom.common.core.domain.req.WxUserInstrumentExportVm;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
@ -15,6 +17,7 @@ import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import com.flossom.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -25,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flossom.system.service.IWxInstrumentSerialService;
import org.springframework.web.multipart.MultipartFile;
/**
* Controller
@ -125,7 +129,7 @@ public class WxInstrumentSerialController extends BaseController
*/
@RequiresPermissions("system:instrumentSerial:remove")
@Log(title = "仪器序列号关联", businessType = BusinessType.DELETE)
@DeleteMapping("/removeAll}")
@DeleteMapping("/removeAll")
public AjaxResult removeAll()
{
return toAjax(wxInstrumentSerialService.deleteAll());
@ -133,7 +137,7 @@ public class WxInstrumentSerialController extends BaseController
/**
*
*
*/
@Log(title = "批量导出", businessType = BusinessType.EXPORT)
@PostMapping("/batchExport")
@ -142,4 +146,26 @@ public class WxInstrumentSerialController extends BaseController
ExcelUtil<WxInstrumentSerialExportVm> util = new ExcelUtil<WxInstrumentSerialExportVm>(WxInstrumentSerialExportVm.class);
util.exportExcel(response, wxInstrumentSerialExportVms, "仪器序列号", wxInstrumentSerial.getExportFields());
}
/**
*
*/
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) throws IOException
{
ExcelUtil<WxInstrumentSerialImportVm> util = new ExcelUtil<WxInstrumentSerialImportVm>(WxInstrumentSerialImportVm.class);
util.importTemplateExcel(response, "仪器序列号导入模板");
}
@Log(title = "仪器序列号", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<WxInstrumentSerialImportVm> util = new ExcelUtil<WxInstrumentSerialImportVm>(WxInstrumentSerialImportVm.class);
List<WxInstrumentSerialImportVm> WxInstrumentSerialImportList = util.importExcel(file.getInputStream());
String message = wxInstrumentSerialService.handleImportData(WxInstrumentSerialImportList);
// String operName = SecurityUtils.getUsername();
// String message = userService.importUser(userList, updateSupport, operName);
return success(message);
}
}

@ -2,6 +2,7 @@ package com.flossom.system.service;
import com.flossom.common.core.domain.entity.WxInstrumentSerial;
import com.flossom.common.core.domain.req.WxInstrumentSerialExportVm;
import com.flossom.common.core.domain.req.WxInstrumentSerialImportVm;
import java.util.List;
@ -83,5 +84,13 @@ public interface IWxInstrumentSerialService
*/
public List<WxInstrumentSerialExportVm> handleExportData(WxInstrumentSerial wxInstrumentSerial);
/**
*
*
* @param wxInstrumentSerialImportVmList list
* @return
*/
public String handleImportData(List<WxInstrumentSerialImportVm> wxInstrumentSerialImportVmList);
}

@ -1,13 +1,22 @@
package com.flossom.system.service.impl;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.flossom.common.core.domain.entity.SysUser;
import com.flossom.common.core.domain.entity.WxInstrument;
import com.flossom.common.core.domain.entity.WxInstrumentSerial;
import com.flossom.common.core.domain.req.WxInstrumentSerialExportVm;
import com.flossom.common.core.domain.req.WxInstrumentSerialImportVm;
import com.flossom.common.core.exception.ServiceException;
import com.flossom.common.core.mapper.WxInstrumentMapper;
import com.flossom.common.core.mapper.WxInstrumentSerialMapper;
import com.flossom.common.core.utils.DateUtils;
import com.flossom.common.core.utils.StringUtils;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -23,8 +32,12 @@ import org.springframework.util.CollectionUtils;
@Service
public class WxInstrumentSerialServiceImpl implements IWxInstrumentSerialService
{
private static final Logger log = LoggerFactory.getLogger(WxInstrumentSerialServiceImpl.class);
@Autowired
private WxInstrumentSerialMapper wxInstrumentSerialMapper;
@Autowired
private WxInstrumentMapper wxInstrumentMapper;
/**
*
@ -65,6 +78,18 @@ public class WxInstrumentSerialServiceImpl implements IWxInstrumentSerialService
public int insertWxInstrumentSerial(WxInstrumentSerial wxInstrumentSerial)
{
wxInstrumentSerial.setCreateTime(DateUtils.getNowDate());
if (Objects.nonNull(wxInstrumentSerial.getInstrumentId())) {
WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(wxInstrumentSerial.getInstrumentId());
if (Objects.nonNull(wxInstrument)) {
wxInstrumentSerial.setInstrumentName(wxInstrument.getName());
}
}
WxInstrumentSerial instrumentSerial = new WxInstrumentSerial();
instrumentSerial.setSerial(wxInstrumentSerial.getSerial());
List<WxInstrumentSerial> wxInstrumentSerials = wxInstrumentSerialMapper.selectWxInstrumentSerialList(instrumentSerial);
if (!CollectionUtils.isEmpty(wxInstrumentSerials)) {
throw new ServiceException("序列号已经存在,请确定后再新增!");
}
return wxInstrumentSerialMapper.insertWxInstrumentSerial(wxInstrumentSerial);
}
@ -152,4 +177,77 @@ public class WxInstrumentSerialServiceImpl implements IWxInstrumentSerialService
}
return resultList;
}
@Override
public String handleImportData(List<WxInstrumentSerialImportVm> wxInstrumentSerialImportVmList) {
if (StringUtils.isNull(wxInstrumentSerialImportVmList) || wxInstrumentSerialImportVmList.size() == 0)
{
throw new ServiceException("导入的仪器序列号数据不能为空!");
}
// 初始化计数器
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (WxInstrumentSerialImportVm instrumentSerialImport : wxInstrumentSerialImportVmList) {
try {
// 先判断仪器ID是否存在
if (Objects.isNull(instrumentSerialImport.getInstrumentId()) || Objects.isNull(instrumentSerialImport.getSerial())){
failureNum++;
failureMsg.append("<br/>" + failureNum + "、仪器ID/序列号不能为空");
} else {
WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(instrumentSerialImport.getInstrumentId());
if (Objects.isNull(wxInstrument)) {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、仪器不存在,请先维护后再导入");
}
WxInstrumentSerial instrumentSerial = new WxInstrumentSerial();
instrumentSerial.setSerial(instrumentSerialImport.getSerial());
List<WxInstrumentSerial> wxInstrumentSerialList = wxInstrumentSerialMapper.selectWxInstrumentSerialList(instrumentSerial);
if (CollectionUtils.isEmpty(wxInstrumentSerialList)) {
if(Objects.nonNull(wxInstrument)) {
// 开始插入数据
WxInstrumentSerial insertRecord = new WxInstrumentSerial();
insertRecord.setCreateTime(DateUtils.getNowDate());
insertRecord.setInstrumentName(wxInstrument.getName());
insertRecord.setSerial(instrumentSerialImport.getSerial());
insertRecord.setSource(instrumentSerialImport.getSource());
insertRecord.setInstrumentId(wxInstrument.getId());
if (StringUtils.isEmpty(instrumentSerialImport.getValidStatus())) {
instrumentSerialImport.setValidStatus("有效") ;
}
insertRecord.setValidStatus(instrumentSerialImport.getValidStatus().trim().equals("有效")?1:0);
wxInstrumentSerialMapper.insertWxInstrumentSerial(insertRecord);
successNum++;
successMsg.append("<br/>" + successNum + "、序列号 " + insertRecord.getSerial() + " 导入成功");
}
} else {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、序列号已经存在");
}
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、仪器ID " + instrumentSerialImport.getInstrumentId() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
log.error(msg, e);
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确");
throw new ServiceException(failureMsg.toString());
}
else
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条:");
}
if (StringUtils.isNotEmpty(successMsg.toString()) && !"null".equals(successMsg.toString())) {
return successMsg.toString();
} else {
return failureMsg.toString();
}
}
}

@ -150,7 +150,7 @@
<span v-show="scope.row.validStatus == 1"></span>
</template>
</el-table-column>
<el-table-column label="来源" align="center" prop="remark" />
<el-table-column label="来源" align="center" prop="source" />
<el-table-column label="创建时间" align="center" prop="createTime" width="100">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
@ -197,7 +197,7 @@
<!-- <el-form-item label="仪器id" prop="instrumentId">-->
<!-- <el-input v-model="form.instrumentId" placeholder="请输入仪器id" />-->
<!-- </el-form-item>-->
<el-form-item label="仪器型号" prop="instrumentName">
<el-form-item label="仪器型号" prop="instrumentId">
<el-select :disabled="isDisabled(form)"
v-model="form.instrumentId"
placeholder="请选择型号"
@ -224,6 +224,42 @@
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 导入对话框 -->
<el-dialog :title="title" :visible.sync="importVisible" width="500px" append-to-body>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="模板下载" prop="serial" >
<el-button
type="primary"
plain
@click="importTemplate"
>点击下载
</el-button>
</el-form-item>
<el-form-item label="模板上传" prop="serial" >
<el-upload
ref="upload"
:limit="1"
accept=".xls, .xlsx"
:headers="upload.headers"
:action="upload.url+ '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传.xls,.xlsx 文件</div>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm"> </el-button>
<el-button @click="importCancel"> </el-button>
</div>
</el-dialog>
<!-- 详情记录对话框 -->
<el-dialog :title="detailTitle" :visible.sync="detailOpen" width="880px" append-to-body>
<el-table v-loading="loading" :data="userInstrumentLogList">
@ -256,7 +292,7 @@
/>
</el-dialog>
<!-- 二维码-->
<!-- 二维码-->
<el-dialog :title="codeTitle" :visible.sync="codeOpen" width="780px" append-to-body>
<div class="demo-image__lazy">
<el-image :key="codeUrl" :src="codeUrl" :preview-src-list="[codeUrl]" lazy></el-image>
@ -312,6 +348,7 @@
<script>
import { listSerial, getSerial, delSerial, addSerial, updateSerial,delSerialAll,updateStatus } from "@/api/system/instrumentSerial";
import {listInstrument} from "@/api/system/instrument";
import {getToken} from "@/utils/auth";
import {listLog} from "@/api/system/userInstrumentLog"
export default {
@ -333,6 +370,8 @@ export default {
instrumentList: [],
//
validStatusVisible: false,
//
importVisible: false,
//
loading: true,
//
@ -391,12 +430,27 @@ export default {
status: null,
instrumentIdArray: null,
},
//
upload: {
//
open: false,
//
title: "",
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: "Bearer " + getToken() },
//
url: process.env.VUE_APP_BASE_API + "/system/instrumentSerial/importData"
},
//
form: {},
//
rules: {
instrumentId: [
{ required: true, message: "仪器id不能为空", trigger: "blur" }
{ required: true, message: "仪器名称不能为空", trigger: "blur" }
],
instrumentName: [
{ required: true, message: "仪器名称不能为空", trigger: "blur" }
@ -443,6 +497,11 @@ export default {
this.open = false;
this.reset();
},
importCancel(){
this.importVisible = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
},
//
reset() {
this.form = {
@ -557,11 +616,15 @@ export default {
if (this.batchOperateValue == 2) {
this.exportFieldsVisible = true;
}
if (this.batchOperateValue == 3) {
this.importVisible = true;
}
if (this.batchOperateValue == 4) {
if (this.ids.length == 0) {
this.$message.error("请选择数据");
return
}
const ids = this.ids;
this.$modal.confirm('确定将选择的数据删除?【请谨慎操作,一旦成功将无法撤销】').then(function() {
return delSerial(ids);
}).then(() => {
@ -665,9 +728,31 @@ export default {
this.exportFieldList.createTime = null;
}
},
//
cancelUpdateStatusDialog (){
this.validStatusVisible = false;
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
//
handleFileSuccess(response, file, fileList, item) {
this.importVisible = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
/** 下载模板操作 */
importTemplate() {
this.download('system/instrumentSerial/importTemplate', {
}, `仪器序列号模板_${new Date().getTime()}.xlsx`)
},
//
submitFileForm() {
this.$refs.upload.submit();
}
}
};
</script>

Loading…
Cancel
Save