Browse Source

[feat]

工程管理 bom信息
新增bom页面导入方法;
ErpBom实体类新增字段levelType;
修改bom后端导入页面的下载模板接口;
新增bom后端导入接口和解析Excel文件方法;
dev
王晓迪 4 months ago
parent
commit
236d9d56ba
  1. 35
      ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java
  2. 24
      ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBom.java
  3. 84
      ruoyi-admin/src/main/resources/templates/erp/bom/bom.html

35
ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java

@ -25,13 +25,17 @@ import org.activiti.engine.task.Task;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.*;
/**
@ -168,9 +172,38 @@ public class ErpBomController extends BaseController
@ResponseBody
public AjaxResult importTemplate()
{
ExcelUtil<ErpBom> util = new ExcelUtil<ErpBom>(ErpBom.class);
ExcelUtil<ErpBomImportVo> util = new ExcelUtil<ErpBomImportVo>(ErpBomImportVo.class);
return util.importTemplateExcel("bom模板");
}
@PostMapping("/importData")
public ResponseEntity<?> handleFileUpload(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport") Boolean updateSupport){
// 处理文件上传
try {
// 验证文件类型
if (!file.getContentType().equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
return ResponseEntity.badRequest().body("无效的文件类型,请上传Excel文件。");
}
List<ErpBomImportVo> erpBomImportVos = readExcelFile(file);
String msg = erpBomService.importData(erpBomImportVos,updateSupport);
// 返回成功消息
return ResponseEntity.status(HttpStatus.OK).body(msg);
} catch (Exception e) {
// 返回错误消息
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("文件上传失败: " + e.getMessage());
}
}
private List<ErpBomImportVo> readExcelFile(MultipartFile file) throws Exception {
// 创建ExcelUtil实例
ExcelUtil<ErpBomImportVo> excelUtil = new ExcelUtil<ErpBomImportVo>(ErpBomImportVo.class);
String filename = file.getOriginalFilename();
// 读取Excel文件
List<ErpBomImportVo> dataList = excelUtil.importExcel(file.getInputStream());
// System.out.println(dataList);
return dataList;
}
/**
* 新增bom
*/

24
ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBom.java

@ -76,6 +76,8 @@ public class ErpBom extends BaseEntity
@Excel(name = "展示层",sort = 1,dictType = "bomLevel")
private Long level;
// @Excel(name = "展示层",sort = 1,dictType = "bomLevel")
private String levelType;
/** 排序 */
private Long sortNo;
@ -139,6 +141,24 @@ public class ErpBom extends BaseEntity
this.documents = documents;
}
public String getLevelType() {
return levelType;
}
public void setLevelType(String levelType) {
this.levelType = levelType;
}
@Override
public Date getUpdateTime() {
return updateTime;
}
@Override
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public void setId(Long id)
{
this.id = id;
@ -279,12 +299,12 @@ public class ErpBom extends BaseEntity
{
return parentId;
}
public void setLevel(Long level)
public void setLevel(Long level)
{
this.level = level;
}
public Long getLevel()
public Long getLevel()
{
return level;
}

84
ruoyi-admin/src/main/resources/templates/erp/bom/bom.html

@ -79,7 +79,7 @@
<a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="erp:bom:export">
<i class="fa fa-download"></i> 导出
</a>
<a class="btn btn-info" onclick="$.table.importExcel()">
<a class="btn btn-info" onclick="importExcel()">
<i class="fa fa-upload"></i> 导入
</a>
<a class="btn btn-success" onclick="bomEqulas()" shiro:hasPermission="erp:bom:equals">
@ -92,7 +92,7 @@
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-fixed-columns-js" />
<!-- <th:block th:include="include :: bootstrap-table-fixed-columns-js" />-->
<script th:src="@{/js/activiti.js}"></script>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('erp:bom:edit')}]];
@ -126,7 +126,7 @@
sortStable: true, // 设置为 true 将获得稳定的排序
modalName: "bom",
detailView: true,
adaptive: true,
// adaptive: true,
fixedColumns: true, // 启用冻结列
rightFixedColumns:1,
fixedRightNumber: 1, // 冻结右列个数
@ -155,11 +155,6 @@
formatter: function(value, row, index) {return $.table.selectDictLabel(processMethodDatas, value);}
},
{ title: '单位',field: 'unit'},
{ title: '流程实例ID',field: 'instanceId',visible: false},
{ title: '流程提交实例ID',field: 'submitInstanceId',visible: false},
{ title: '流程作废实例ID', field: 'cancelInstanceId',visible: false},
{ title: '流程恢复实例ID',field: 'restoreInstanceId',visible: false},
{ title: '流程实例类型',field: 'instanceTypeName', visible: false},
{ title: '图片',field: 'photoUrl',formatter: function(value, row, index) {return $.table.imageView(value);}},
{ title: '<span style="color: red;">申请人</span>',field: 'applyUserName',
formatter: function(value, row, index) {return '<span style="color: red;">' + (value ? value : "-") + '</span>';}
@ -171,24 +166,28 @@
return '<span class="badge badge-primary">' + value + '</span>';
}
},
{ title: '流程实例ID',field: 'instanceId',visible: false},
{ title: '流程提交实例ID',field: 'submitInstanceId',visible: false},
{ title: '流程作废实例ID', field: 'cancelInstanceId',visible: false},
{ title: '流程恢复实例ID',field: 'restoreInstanceId',visible: false},
{ title: '流程实例类型',field: 'instanceTypeName', visible: false},
{ title: '申请人ID',field: 'applyUser',visible: false},
{ title: '当前任务ID',field: 'taskId',visible: false,},
{ title: '待办用户ID',field: 'todoUserId',visible: false,},
{ title: '审核状态',field: 'auditStatus',sortable: true,visible: false,
{ title: '审核状态',field: 'auditStatus',visible: false,
formatter: function(value, row, index) {
return $.table.selectDictLabel(auditStatusDatas, value);
}
},
{ title: '使用状态',field: 'useStatus',sortable: true,visible: false,
{ title: '使用状态',field: 'useStatus',visible: false,
formatter: function(value, row, index) {
return $.table.selectDictLabel(useStatusDatas, value);
}
},
{ title: '工程员',field: 'engineer', sortable: true,visible: false},
{ title: '物料类型',field: 'materialType',sortable: true,visible: false,
{ title: '工程员',field: 'engineer', visible: false},
{ title: '物料类型',field: 'materialType',visible: false,
formatter: function(value, row, index) {return $.table.selectCategoryLabel(materialTypeDatas, value);}},
{ title: '加工方式',field: 'processMethod',sortable: true,visible: false,
{ title: '加工方式',field: 'processMethod',visible: false,
formatter: function(value, row, index) {return $.table.selectDictLabel(processMethodDatas, value);}
},
{ title: '父级id',field: 'parentId',visible:false },
@ -746,6 +745,7 @@
}
});
}
// 导出
function exportExcel(formId) {
// $.table.set();
var bomNoData = [];
@ -800,6 +800,62 @@
});
}
};
// 导入
function importExcel(formId, width, height) {
table.set();
var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
var _width = $.common.isEmpty(width) ? "400" : width;
var _height = $.common.isEmpty(height) ? "230" : height;
layer.open({
type: 1,
area: [_width + 'px', _height + 'px'],
fix: false,
// 不固定
maxmin: true,
shade: 0.3,
title: '导入' + table.options.modalName + '数据',
content: $('#' + currentId).html(),
btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
// 弹层外区域关闭
shadeClose: true,
btn1: function(index, layero){
var file = layero.find('#file').val();
if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
$.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
return false;
}
var index = layer.load(2, {shade: false});
$.modal.disable();
// 获取CheckBox的状态
var updateSupport = layero.find('#updateSupport').is(':checked');
var formData = new FormData(layero.find('form')[0]);
formData.append('updateSupport', updateSupport); // 添加CheckBox的状态到FormData
$.ajax({
url: table.options.importUrl,
data: formData,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (result) {
layer.close(index);
$.modal.enable();
$.modal.closeAll();
$.modal.alertSuccess(result);
$.table.refresh();
},
error: function (result){
layer.close(index);
$.modal.alertError(result);
}
});
}
});
}
</script>
</body>
<!-- 导入区域 -->

Loading…
Cancel
Save