版本:3.4.0
我使用的是3.5.0的框架生成的代码。
各业务部门,重要设备有各自组件,组件有购入,借调,报废等组件状态,以及及日常生产参数数据。
组件档案是单表数据:原料+型号,可以确定它能生产那种规格产品
重要字段:设备分类(字典数据)
,组件名称
,规格型号
其他字段:物料编码,组件参数1,组件参数2,组件参数3,组件参数4,组件参数5,原料规格(字典数据
),产品规格(字典数据
)
公用字段:创建人,创建时间,更新人,更新时间,状态
另外需要预留五个字段。
CREATE TABLE `asset_archives` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
`category_id` bigint(20) NOT NULL COMMENT '设备分类id',
`asset_name` varchar(255) NOT NULL COMMENT '组件名称',
`material_code` varchar(255) DEFAULT '' COMMENT '物料编码',
`asset_model` varchar(255) DEFAULT '' COMMENT '规格型号',
`classification` varchar(255) DEFAULT '' COMMENT '分类大类',
`asset_param1` varchar(255) DEFAULT '' COMMENT '组件参数1',
`asset_param2` varchar(255) DEFAULT '' COMMENT '组件参数2',
`asset_param3` varchar(255) DEFAULT '' COMMENT '组件参数3',
`asset_param4` varchar(255) DEFAULT '' COMMENT '组件参数4',
`asset_param5` varchar(255) DEFAULT '' COMMENT '组件参数5',
`raw_code` varchar(5) DEFAULT '' COMMENT '原料规格',
`product_code` varchar(5) DEFAULT '' COMMENT '产品规格',
`create_by` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`update_by` varchar(255) DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`status` varchar(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
`reserve1` varchar(255) DEFAULT '' COMMENT '预留字段1',
`reserve2` varchar(255) DEFAULT '' COMMENT '预留字段2',
`reserve3` varchar(255) DEFAULT '' COMMENT '预留字段3',
`reserve4` varchar(255) DEFAULT '' COMMENT '预留字段4',
`reserve5` varchar(255) DEFAULT '' COMMENT '预留字段5',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='组件档案表';
产品规格:raw_code
原料规格:product_code
这两个字段都是由生产部门员工维护,因此在开发的时候,这两个字典数据的值,以简单的产品1,2,3,4,5和原料1,2,3,4,5代替。
前端页面只有2个,一个是vue文件,一个是js文件
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="设备分类" prop="categoryId">
<el-select v-model="queryParams.categoryId" placeholder="请选择资产分类" clearable size="small">
<el-option
v-for="item in categoryOptions"
:key="item.id"
:label="item.categoryName"
:value="item.id"
/>
el-select>
el-form-item>
<el-form-item label="组件名称" prop="assetName">
<el-input
v-model="queryParams.assetName"
placeholder="请输入组件名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
el-form-item>
<el-form-item label="物料编码" prop="materialCode">
<el-input
v-model="queryParams.materialCode"
placeholder="请输入物料编码"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
el-select>
el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置el-button>
el-form-item>
el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['hxems:archives:add']"
>新增el-button>
el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['hxems:archives:edit']"
>修改el-button>
el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['hxems:archives:remove']"
>删除el-button>
el-col>
<el-col :span="1.5">
<el-button
type="info"
plain
icon="el-icon-upload2"
size="mini"
@click="handleImport"
v-hasPermi="['hxems:archives:import']"
>导入el-button>
el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
:loading="exportLoading"
@click="handleExport"
v-hasPermi="['hxems:archives:export']"
>导出el-button>
el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList">right-toolbar>
el-row>
<el-table v-loading="loading" :data="archivesList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="设备分类" align="center" prop="categoryName" />
<el-table-column label="组件名称" align="center" prop="assetName" />
<el-table-column label="物料编码" align="center" prop="materialCode" />
<el-table-column label="规格型号" align="center" prop="assetModel" />
<el-table-column label="分类大类" align="center" prop="classification" :formatter="classificationFormat" />
<el-table-column label="组件参数1" align="center" prop="assetParam1" />
<el-table-column label="组件参数2" align="center" prop="assetParam2" />
<el-table-column label="原料规格" align="center" prop="rawCode" :formatter="rawCodeFormat" />
<el-table-column label="产品规格" align="center" prop="productCode" :formatter="productCodeFormat" />
<el-table-column label="创建人" align="center" prop="createBy" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}span>
template>
el-table-column>
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['hxems:archives:edit']"
>修改el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['hxems:archives:remove']"
>删除el-button>
template>
el-table-column>
el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-row>
<el-col :span="12">
<el-form-item label="设备分类" prop="categoryId">
<el-select v-model="form.categoryId" placeholder="请选择设备分类">
<el-option
v-for="item in categoryOptions"
:key="item.id"
:label="item.categoryName"
:value="item.id"
/>
el-select>
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="组件名称" prop="assetName">
<el-input v-model="form.assetName" placeholder="请输入组件名称" />
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="物料编码" prop="materialCode">
<el-input v-model="form.materialCode" placeholder="请输入物料编码" />
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="规格型号" prop="assetModel">
<el-input v-model="form.assetModel" placeholder="请输入规格型号" />
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="分类" prop="classification">
<el-select v-model="form.classification" placeholder="请选择分类">
<el-option
v-for="dict in classificationOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
:disabled="dict.status == 1"
>el-option>
el-select>
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="组件参数1" prop="assetParam1">
<el-input v-model="form.assetParam1" placeholder="请输入组件参数1" />
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="组件参数2" prop="assetParam2">
<el-input v-model="form.assetParam2" placeholder="请输入组件参数2" />
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="组件参数3" prop="assetParam3">
<el-input v-model="form.assetParam3" placeholder="请输入组件参数3" />
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="组件参数4" prop="assetParam4">
<el-input v-model="form.assetParam4" placeholder="请输入组件参数4" />
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="组件参数5" prop="assetParam5">
<el-input v-model="form.assetParam5" placeholder="请输入组件参数5" />
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="原料规格" prop="rawCode">
<el-select v-model="form.rawCode" placeholder="请选择原料规格">
<el-option
v-for="dict in rawCodeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
:disabled="dict.status == 1"
>el-option>
el-select>
el-form-item>
el-col>
<el-col :span="12">
<el-form-item label="产品规格" prop="productCode">
<el-select v-model="form.productCode" placeholder="请选择产品规格">
<el-option
v-for="dict in productCodeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
:disabled="dict.status == 1"
>el-option>
el-select>
el-form-item>
el-col>
el-row>
<el-row>
<el-col :span="12">
<el-form-item label="状态">
<el-radio-group v-model="form.status">
<el-radio
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictValue"
>{{dict.dictLabel}}el-radio>
el-radio-group>
el-form-item>
el-col>
el-row>
el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定el-button>
<el-button @click="cancel">取 消el-button>
div>
el-dialog>
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
ref="upload"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url"
: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 text-center" slot="tip">
<span style="color:#ff0000">仅允许导入xls、xlsx格式文件。span>
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板el-link>
div>
el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm">确 定el-button>
<el-button @click="upload.open = false">取 消el-button>
div>
el-dialog>
div>
template>
<script>
import { listCategory } from '@/api/hxems/category'
import { getToken } from '@/utils/auth'
import { listArchives, getArchives, delArchives, addArchives, updateArchives, importTemplate, exportArchives } from "@/api/hxems/archives";
export default {
name: "Archives",
components: {
},
data() {
return {
// 遮罩层
loading: true,
// 导出遮罩层
exportLoading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 组件档案表格数据
archivesList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 分类大类字典
classificationOptions: [],
// 资产分类字典数据
categoryOptions:[],
// 原料规格字典
rawCodeOptions: [],
// 产品规格字典
productCodeOptions: [],
// 状态字典
statusOptions: [],
// 组件导入参数
upload: {
// 是否显示弹出层(组件导入)
open: false,
// 弹出层标题(组件导入)
title: "",
// 是否禁用上传
isUploading: false,
// 设置上传的请求头部
headers: { Authorization: "Bearer " + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + "/3/archives/importData"
},
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
categoryId: null,
assetName: null,
materialCode: null,
status: '0',
},
// 表单参数
form: {},
// 表单校验
rules: {
categoryId: [
{ required: true, message: "设备分类不能为空", trigger: "change" }
],
assetName: [
{ required: true, message: "组件名称不能为空", trigger: "blur" }
],
materialCode: [
{ required: true, message: "物料编码不能为空", trigger: "blur" }
],
}
};
},
created() {
this.getList();
this.getCategoryList();
this.getDicts("team_classification").then(response => {
this.classificationOptions = response.data;
});
this.getDicts("raw_code").then(response => {
this.rawCodeOptions = response.data;
});
this.getDicts("product_code").then(response => {
this.productCodeOptions = response.data;
});
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
},
methods: {
/** 查询组件管理列表 */
getList() {
this.loading = true;
listArchives(this.queryParams).then(response => {
this.archivesList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 分类字典翻译
classificationFormat(row, column) {
return this.selectDictLabel(this.classificationOptions, row.classification);
},
// 原料规格字典翻译
rawCodeFormat(row, column) {
return this.selectDictLabel(this.rawCodeOptions, row.rawCode);
},
// 产品规格字典翻译
productCodeFormat(row, column) {
return this.selectDictLabel(this.productCodeOptions, row.productCode);
},
// 状态字典翻译
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: null,
categoryId: null,
assetName: null,
materialCode: null,
assetModel: null,
classification: null,
assetParam1: null,
assetParam2: null,
assetParam3: null,
assetParam4: null,
assetParam5: null,
rawCode: null,
productCode: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
status: "0",
reserve1: null,
reserve2: null,
reserve3: null,
reserve4: null,
reserve5: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加组件档案";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getArchives(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改组件档案";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateArchives(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addArchives(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除组件档案编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delArchives(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
})
},
getCategoryList() {
listCategory().then(response => {
this.categoryOptions = response.rows;
});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有组件档案数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.exportLoading = true;
return exportArchives(queryParams);
}).then(response => {
this.download(response.msg);
this.exportLoading = false;
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = "组件档案导入";
this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
importTemplate().then(response => {
this.download(response.msg);
});
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert(" ", "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
// 提交上传文件
submitFileForm() {
this.$refs.upload.submit();
}
}
}
script>
import request from '@/utils/request'
// 查询组件管理列表
export function listArchives(query) {
return request({
url: '/archives/list',
method: 'get',
params: query
})
}
// 查询组件管理详细
export function getArchives(id) {
return request({
url: '/archives/' + id,
method: 'get'
})
}
// 新增组件管理
export function addArchives(data) {
return request({
url: '/archives',
method: 'post',
data: data
})
}
// 修改组件管理
export function updateArchives(data) {
return request({
url: '/archives',
method: 'put',
data: data
})
}
// 删除组件管理
export function delArchives(id) {
return request({
url: '/archives/' + id,
method: 'delete'
})
}
// 导出组件管理
export function exportArchives(query) {
return request({
url: '/archives/export',
method: 'get',
params: query
})
}
// 下载用户导入模板
export function importTemplate() {
return request({
url: '/archives/importTemplate',
method: 'get'
})
}
后端的类比较多,有控制器,有service,还有entity,swagger也需要改
package com.shhx.hxems.api.controller.v1.asset;
import com.shhx.hxems.annotation.Log;
import com.shhx.hxems.app.service.IAssetArchivesService;
import com.shhx.hxems.config.SwaggerTags;
import com.shhx.hxems.core.BaseController;
import com.shhx.hxems.core.domain.AjaxResult;
import com.shhx.hxems.core.domain.asset.AssetArchives;
import com.shhx.hxems.core.domain.entity.SysUser;
import com.shhx.hxems.core.page.TableDataInfo;
import com.shhx.hxems.enums.BusinessType;
import com.shhx.hxems.utils.DateUtils;
import com.shhx.hxems.utils.SecurityUtils;
import com.shhx.hxems.utils.StringUtils;
import com.shhx.hxems.utils.poi.ExcelUtil;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 组件档案Controller
* @date 2022-03-07
*/
@Api(tags = SwaggerTags.ASSETARCHIVES)
@RestController
@RequestMapping("/v1/{organizationId}/archives")
public class AssetArchivesController extends BaseController
{
@Autowired
private IAssetArchivesService assetArchivesService;
/**
* 查询组件档案列表
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:list')")
@GetMapping("/list")
public TableDataInfo list(AssetArchives assetArchives)
{
startPage();
List<AssetArchives> list = assetArchivesService.selectAssetArchivesList(assetArchives);
return getDataTable(list);
}
/**
* 导出组件档案列表
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:export')")
@Log(title = "组件档案", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(AssetArchives assetArchives)
{
List<AssetArchives> list = assetArchivesService.selectAssetArchivesList(assetArchives);
ExcelUtil<AssetArchives> util = new ExcelUtil<AssetArchives>(AssetArchives.class);
return util.exportExcel(list, "组件档案数据");
}
/**
* 获取组件档案详细信息
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
AjaxResult ajax = AjaxResult.success();
// ajax.put("categoryOptions", assetArchivesService.selectCategoryAll());
if (StringUtils.isNotNull(id)){
AssetArchives assetArchives = assetArchivesService.selectAssetArchivesById(id);
ajax.put(AjaxResult.DATA_TAG, assetArchives);
}
return ajax;
}
/**
* 新增组件档案
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:add')")
@Log(title = "组件档案", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody AssetArchives assetArchives)
{
assetArchives.setCreateTime(DateUtils.getNowDate());
assetArchives.setCreateBy(SecurityUtils.getUsername());
return toAjax(assetArchivesService.insertAssetArchives(assetArchives));
}
/**
* 修改组件档案
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:edit')")
@Log(title = "组件档案", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody AssetArchives assetArchives)
{
assetArchives.setUpdateBy(SecurityUtils.getUsername());
assetArchives.setUpdateTime(DateUtils.getNowDate());
return toAjax(assetArchivesService.updateAssetArchives(assetArchives));
}
/**
* 删除组件档案
*/
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
@PreAuthorize("@ss.hasPermi('hxems:archives:remove')")
@Log(title = "组件档案", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(assetArchivesService.deleteAssetArchivesByIds(ids));
}
/**
* 导出组件档案模板
*/
@GetMapping("/importTemplate")
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
public AjaxResult importTemplate()
{
ExcelUtil<AssetArchives> util = new ExcelUtil<>(AssetArchives.class);
return util.importTemplateExcel("组件档案模板");
}
/**
* 导入组件档案列表
*/
@Log(title = "组件管理", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('hxems:archives:import')")
@PostMapping("/importData")
@Permission(level = ResourceLevel.SITE, permissionLogin = true)
public AjaxResult importData(MultipartFile file) throws Exception
{
ExcelUtil<AssetArchives> util = new ExcelUtil<>(AssetArchives.class);
List<AssetArchives> assetArchivesList = util.importExcel(file.getInputStream());
String message = assetArchivesService.importAssetArchives(assetArchivesList);
return AjaxResult.success(message);
}
}
package com.shhx.hxems.app.service;
import java.util.List;
import com.shhx.hxems.core.domain.asset.AssetArchives;
/**
* 组件管理Service接口
*/
public interface IAssetArchivesService{
/**
* 查询组件管理
*/
public AssetArchives selectAssetArchivesById(Long id);
/**
* 查询组件管理列表
*/
public List<AssetArchives> selectAssetArchivesList(AssetArchives assetArchives);
/**
* 新增组件管理
*/
public int insertAssetArchives(AssetArchives assetArchives);
/**
* 修改组件管理
*/
public int updateAssetArchives(AssetArchives assetArchives);
/**
* 批量删除组件管理
*/
public int deleteAssetArchivesByIds(Long[] ids);
/**
* 删除组件管理信息
*/
public int deleteAssetArchivesById(Long id);
String importAssetArchives(List<AssetArchives> assetArchivesList);
}
package com.shhx.hxems.app.service.impl;
import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.shhx.hxems.utils.DateUtils;
import com.shhx.hxems.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shhx.hxems.mapper.AssetArchivesMapper;
import com.shhx.hxems.core.domain.asset.AssetArchives;
import com.shhx.hxems.app.service.IAssetArchivesService;
import javax.validation.Validator;
/**
* 组件管理Service业务层处理
*/
@Service
public class AssetArchivesServiceImpl implements IAssetArchivesService
{
private static final Logger log = LoggerFactory.getLogger(AssetArchivesServiceImpl.class);
@Autowired
private AssetArchivesMapper assetArchivesMapper;
@Autowired
protected Validator validator;
/**
* 查询组件管理
*/
@Override
public AssetArchives selectAssetArchivesById(Long id)
{
return assetArchivesMapper.selectAssetArchivesById(id);
}
/**
* 查询组件管理列表
*/
@Override
public List<AssetArchives> selectAssetArchivesList(AssetArchives assetArchives)
{
return assetArchivesMapper.selectAssetArchivesList(assetArchives);
}
/**
* 新增组件管理
*/
@Override
public int insertAssetArchives(AssetArchives assetArchives)
{
assetArchives.setCreateTime(DateUtils.getNowDate());
return assetArchivesMapper.insertAssetArchives(assetArchives);
}
/**
* 修改组件管理
*/
@Override
public int updateAssetArchives(AssetArchives assetArchives)
{
assetArchives.setUpdateTime(DateUtils.getNowDate());
return assetArchivesMapper.updateAssetArchives(assetArchives);
}
/**
* 批量删除组件管理
*/
@Override
public int deleteAssetArchivesByIds(Long[] ids)
{
return assetArchivesMapper.deleteAssetArchivesByIds(ids);
}
/**
* 删除组件管理信息
*/
@Override
public int deleteAssetArchivesById(Long id)
{
return assetArchivesMapper.deleteAssetArchivesById(id);
}
@Override
public String importAssetArchives(List<AssetArchives> assetArchivesList) {
{
if (StringUtils.isNull(assetArchivesList) || assetArchivesList.size() == 0) {
throw new ServiceException("导入组件数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (AssetArchives archives : assetArchivesList) {
try {
archives.setCreateBy(SecurityUtils.getUsername());
archives.setCreateTime(com.ruoyi.common.utils.DateUtils.getNowDate());
this.insertAssetArchives(archives);
successNum++;
successMsg.append("
" + successNum + "、组件名称 " + archives.getAssetName() + " 导入成功");
} catch (Exception e) {
failureNum++;
String msg = "
" + failureNum + "、组件名称 " + archives.getAssetName() + " 导入失败:";
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 + " 条,数据如下:");
}
return successMsg.toString();
}
}
}
package com.shhx.hxems.core.domain.asset;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.shhx.hxems.annotation.Excel;
import com.shhx.hxems.annotation.Excel.Type;
import com.shhx.hxems.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 组件管理对象 asset_archives
*/
public class AssetArchives extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键id */
private Long id;
/** 设备分类 */
@Excel(name = "设备分类ID")
private Long categoryId;
/** 设备分类名称 */
@Excel(name = "设备分类名称", type = Type.EXPORT)
private String categoryName;
/** 组件名称 */
@Excel(name = "组件名称")
private String assetName;
/** 物料编码 */
@Excel(name = "物料编码")
private String materialCode;
/** 规格型号 */
@Excel(name = "规格型号")
private String assetModel;
/** 分类大类 */
@Excel(name = "分类")
private String classification;
/** 组件参数1 */
@Excel(name = "组件参数1")
private String assetParam1;
/** 组件参数2 */
@Excel(name = "组件参数2")
private String assetParam2;
/** 组件参数3 */
@Excel(name = "组件参数3")
private String assetParam3;
/** 组件参数4 */
@Excel(name = "组件参数4")
private String assetParam4;
/** 组件参数5 */
@Excel(name = "组件参数5")
private String assetParam5;
/** 原料规格 */
@Excel(name = "原料规格")
private String rawCode;
/** 产品规格 */
@Excel(name = "产品规格")
private String productCode;
/** 状态(0正常 1停用) */
@Excel(name = "状态", type = Type.EXPORT, readConverterExp = "0=正常,1=停用")
private String status;
/** 预留字段1 */
@JsonIgnore
private String reserve1;
/** 预留字段2 */
@JsonIgnore
private String reserve2;
/** 预留字段3 */
@JsonIgnore
private String reserve3;
/** 预留字段4 */
@JsonIgnore
private String reserve4;
/** 预留字段5 */
@JsonIgnore
private String reserve5;
}
注意controller有个注解 @Api(tags = SwaggerTags.ASSETARCHIVES)
,该值需要在SwaggerTags类中进行配置。
public static final String ASSETARCHIVES = “AssetArchives”;