Browse Source

修改物料导入功能,添加单价

lwx_dev
erdanergou 3 years ago
parent
commit
8ec13562b7
  1. 4
      src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfo.java
  2. 20
      src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java
  3. 62
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  4. BIN
      src/main/resources/static/upload/materialImport.xlsx
  5. 108
      src/main/resources/templates/pages/depository/table-stock.html
  6. 106
      src/main/resources/templates/pages/material/material-out.html
  7. 103
      src/main/resources/templates/pages/materialtype/materialType_view.html
  8. BIN
      target/classes/static/upload/materialImport.xlsx

4
src/main/java/com/dreamchaser/depository_manage/entity/ExcelInfo.java

@ -39,6 +39,10 @@ public class ExcelInfo {
@ExcelProperty("编码") @ExcelProperty("编码")
private String code; private String code;
/**单价**/
@ExcelProperty(value = "单价")
private String price;
/** 规格型号 */ /** 规格型号 */
@ExcelProperty("规格型号") @ExcelProperty("规格型号")
private String version; private String version;

20
src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java

@ -86,18 +86,18 @@ public class ExcelServiceImpl implements ExcelService {
taskCenterUtil.submitTask(() -> { taskCenterUtil.submitTask(() -> {
List<Object> success = new ArrayList<>(); List<Object> success = new ArrayList<>();
Map<String, Object> returnResult = new HashMap<>(); Map<String, Object> returnResult = new HashMap<>();
for (ExcelInfo excelVo : excelVos) {
for (int i = 0; i < excelVos.size(); i++) {
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("mname", excelVos.get(i).getMname()); param.put("mname", excelVo.getMname());
param.put("code", excelVos.get(i).getCode()); param.put("code", excelVo.getCode());
param.put("unit", excelVos.get(i).getUnit()); param.put("unit", excelVo.getUnit());
param.put("version", excelVos.get(i).getVersion()); param.put("version", excelVo.getVersion());
param.put("texture", excelVos.get(i).getTexture()); param.put("texture", excelVo.getTexture());
param.put("materialTypeId", excelVos.get(i).getTypeId()); param.put("materialTypeId", excelVo.getTypeId());
param.put("id", excelVos.get(i).getId()); param.put("id", excelVo.getId());
param.put("price",excelVo.getPrice() == null ? "0" : excelVo.getPrice());
materialService.insertMaterial(param); materialService.insertMaterial(param);
success.add(excelVos.get(i)); success.add(excelVo);
} }
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos)); log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos));

62
src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java

@ -80,11 +80,9 @@ public class MaterialServiceImpl implements MaterialService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public Integer insertMaterial(Map<String, Object> map) { public Integer insertMaterial(Map<String, Object> map) {
if (map.containsKey("quantity") && map.containsKey("price")) { if (map.containsKey("price")) {
int quantity = (int) Math.round(Double.parseDouble(map.get("quantity").toString()));
int price = (int) (Double.parseDouble(map.get("price").toString()) * 100); int price = (int) (Double.parseDouble(map.get("price").toString()) * 100);
map.put("price", price); map.put("price", price);
map.put("amounts", quantity * price);
} }
// 判断是否有保质期 // 判断是否有保质期
Integer shelfLife = 0; Integer shelfLife = 0;
@ -214,10 +212,10 @@ public class MaterialServiceImpl implements MaterialService {
map.put("state", state); map.put("state", state);
List<Material> list = materialMapper.findMaterialByCondition(map); List<Material> list = materialMapper.findMaterialByCondition(map);
for (Material material : list) { for (Material material : list) {
if(material.getPrice() != null){ if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
}else{ } else {
material.setPrice(0.0); material.setPrice(0.0);
} }
material.setAmounts(material.getPrice() * material.getQuantity()); material.setAmounts(material.getPrice() * material.getQuantity());
@ -267,9 +265,9 @@ public class MaterialServiceImpl implements MaterialService {
} }
map.put("state", state); map.put("state", state);
List<Material> materialByCondition = materialMapper.findMaterialByCondition(map); List<Material> materialByCondition = materialMapper.findMaterialByCondition(map);
for (Material material:materialByCondition for (Material material : materialByCondition
) { ) {
if(material.getPrice() != null){ if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
} }
} }
@ -373,7 +371,7 @@ public class MaterialServiceImpl implements MaterialService {
} }
List<Material> list = materialMapper.findMaterialByCondition(map); List<Material> list = materialMapper.findMaterialByCondition(map);
for (Material material : list) { for (Material material : list) {
if(material.getPrice() == null){ if (material.getPrice() == null) {
material.setPrice(0.0); material.setPrice(0.0);
} }
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
@ -441,7 +439,7 @@ public class MaterialServiceImpl implements MaterialService {
public List<Material> findMaterialAll() { public List<Material> findMaterialAll() {
List<Material> materialList = materialMapper.findMaterialByCondition(new HashMap<String, Object>()); List<Material> materialList = materialMapper.findMaterialByCondition(new HashMap<String, Object>());
for (Material material : materialList) { for (Material material : materialList) {
if(material.getPrice() == null){ if (material.getPrice() == null) {
material.setPrice(0.0); material.setPrice(0.0);
} }
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
@ -461,10 +459,10 @@ public class MaterialServiceImpl implements MaterialService {
Material material = materialMapper.findMaterialById(id); Material material = materialMapper.findMaterialById(id);
MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(material.getMaterialTypeId()); MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(material.getMaterialTypeId());
material.setTypeName(materialTypeByOldId.getTname()); material.setTypeName(materialTypeByOldId.getTname());
if(material.getPrice() != null){ if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
}else{ } else {
material.setPrice(0.0); material.setPrice(0.0);
} }
material.setAmounts(material.getPrice() * material.getQuantity()); material.setAmounts(material.getPrice() * material.getQuantity());
@ -501,13 +499,13 @@ public class MaterialServiceImpl implements MaterialService {
for (Inventory inventory : inventoryByMid) { for (Inventory inventory : inventoryByMid) {
MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(inventory.getMaterialTypeId()); MaterialType materialTypeByOldId = materialTypeMapper.findMaterialTypeByOldId(inventory.getMaterialTypeId());
inventory.setTypeName(materialTypeByOldId.getTname()); inventory.setTypeName(materialTypeByOldId.getTname());
if(inventory.getPlaceCode() != null){ if (inventory.getPlaceCode() != null) {
inventory.setPrice(inventory.getPrice() / 100); inventory.setPrice(inventory.getPrice() / 100);
}else{ } else {
inventory.setPrice(0.0); inventory.setPrice(0.0);
} }
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity()); inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
} }
return inventoryByMid; return inventoryByMid;
} }
@ -621,10 +619,10 @@ public class MaterialServiceImpl implements MaterialService {
public List<Inventory> findMaterialByIds(List<Integer> ids) { public List<Inventory> findMaterialByIds(List<Integer> ids) {
List<Inventory> materialList = materialMapper.findInventoryByIds(ids); List<Inventory> materialList = materialMapper.findInventoryByIds(ids);
for (Inventory material : materialList) { for (Inventory material : materialList) {
if(material.getPrice() != null){ if (material.getPrice() != null) {
material.setPrice(material.getPrice() / 100); material.setPrice(material.getPrice() / 100);
}else{ } else {
material.setPrice(0.0); material.setPrice(0.0);
} }
@ -820,7 +818,7 @@ public class MaterialServiceImpl implements MaterialService {
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity); splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity);
} }
if(inventory.getPrice() == null){ if (inventory.getPrice() == null) {
inventory.setPrice(0.0); inventory.setPrice(0.0);
} }
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / splitInfo.getQuantity()); BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / splitInfo.getQuantity());
@ -1095,7 +1093,7 @@ public class MaterialServiceImpl implements MaterialService {
if (materialAndBarCode.getIid() != null) { if (materialAndBarCode.getIid() != null) {
Inventory inventoryByMid = materialMapper.findInventoryById(materialAndBarCode.getIid()); Inventory inventoryByMid = materialMapper.findInventoryById(materialAndBarCode.getIid());
if (inventoryByMid != null) { if (inventoryByMid != null) {
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
materialAndBarCode.setPrice(inventoryByMid.getPrice() / 100); materialAndBarCode.setPrice(inventoryByMid.getPrice() / 100);
@ -1537,7 +1535,7 @@ public class MaterialServiceImpl implements MaterialService {
Map<String, Object> insertForSplitInventory = new HashMap<>(); Map<String, Object> insertForSplitInventory = new HashMap<>();
insertForSplitInventory.put("mid", inventoryByMid.getMid()); insertForSplitInventory.put("mid", inventoryByMid.getMid());
insertForSplitInventory.put("mcode", inventoryByMid.getCode()); insertForSplitInventory.put("mcode", inventoryByMid.getCode());
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
insertForSplitInventory.put("price", inventoryByMid.getPrice() / scale); insertForSplitInventory.put("price", inventoryByMid.getPrice() / scale);
@ -1555,7 +1553,7 @@ public class MaterialServiceImpl implements MaterialService {
// 定义进制时算法需要的参数 // 定义进制时算法需要的参数
Map<String, Object> paramForNewMap = new HashMap<>(); Map<String, Object> paramForNewMap = new HashMap<>();
paramForNewMap.put("mid", inventoryByMid.getMid()); paramForNewMap.put("mid", inventoryByMid.getMid());
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
paramForNewMap.put("price", String.valueOf(inventoryByMid.getPrice() / 100)); paramForNewMap.put("price", String.valueOf(inventoryByMid.getPrice() / 100));
@ -1594,13 +1592,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo); splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo);
} else { } else {
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100)); paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose)); paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose)); paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false); depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id"))); depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
} }
// 调用新算法 // 调用新算法
@ -1641,13 +1639,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo); splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, pidAndMidForAfter.getId(), paramForNewMap, quantity, splitInfo);
} else { } else {
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100)); paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose)); paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose)); paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false); depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id"))); depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
} }
} else { } else {
@ -1690,13 +1688,13 @@ public class MaterialServiceImpl implements MaterialService {
SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId()); SplitInfo parentSplitInfo = splitUnitMapper.findSplitInfoById(splitInfo.getParentId());
splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, ObjectFormatUtil.toInteger(insertForSplitInventory.get("id")), paramForNewMap, quantity, splitInfo); splitUnitService.updateSplitInfoSaveQuantity(parentSplitInfo, dispose, ObjectFormatUtil.toInteger(insertForSplitInventory.get("id")), paramForNewMap, quantity, splitInfo);
} else { } else {
if(inventoryByMid.getPrice() == null){ if (inventoryByMid.getPrice() == null) {
inventoryByMid.setPrice(0.0); inventoryByMid.setPrice(0.0);
} }
paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100)); paramForNewMap.put("price", Double.toString(inventoryByMid.getPrice() / 100));
paramForNewMap.put("realQuantity", String.valueOf(dispose)); paramForNewMap.put("realQuantity", String.valueOf(dispose));
paramForNewMap.put("quantity", String.valueOf(dispose)); paramForNewMap.put("quantity", String.valueOf(dispose));
depositoryRecordService.applicationInPlace(paramForNewMap,false); depositoryRecordService.applicationInPlace(paramForNewMap, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id"))); depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(paramForNewMap.get("id")));
} }
@ -2419,7 +2417,6 @@ public class MaterialServiceImpl implements MaterialService {
} }
// 构造树形组件数据模板 // 构造树形组件数据模板
public Map<String, Object> InitTreeMenus_New(MaterialType mt, List<Object> children) { public Map<String, Object> InitTreeMenus_New(MaterialType mt, List<Object> children) {
if (mt != null) { if (mt != null) {
@ -2585,6 +2582,7 @@ public class MaterialServiceImpl implements MaterialService {
/** /**
* 获取当前仓库列表下的库存数量 * 获取当前仓库列表下的库存数量
*
* @param depositoryIds 待查询仓库列表 * @param depositoryIds 待查询仓库列表
* @return * @return
*/ */

BIN
src/main/resources/static/upload/materialImport.xlsx

Binary file not shown.

108
src/main/resources/templates/pages/depository/table-stock.html

@ -30,19 +30,22 @@
<div class="layui-inline"> <div class="layui-inline">
<label class="layui-form-label">物料名称</label> <label class="layui-form-label">物料名称</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="mname" autocomplete="off" class="layui-input" placeholder="请填写物料名称"> <input type="text" name="mname" autocomplete="off" class="layui-input"
placeholder="请填写物料名称">
</div> </div>
</div> </div>
<div class="layui-inline"> <div class="layui-inline">
<label class="layui-form-label">存货编码</label> <label class="layui-form-label">存货编码</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="code" autocomplete="off" class="layui-input" placeholder="请填写物料编码"> <input type="text" name="code" autocomplete="off" class="layui-input"
placeholder="请填写物料编码">
</div> </div>
</div> </div>
<div class="layui-inline"> <div class="layui-inline">
<label class="layui-form-label">型号</label> <label class="layui-form-label">型号</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" class="layui-input" id="version" name="version" autocomplete="off" placeholder="请填写物料型号"/> <input type="text" class="layui-input" id="version" name="version" autocomplete="off"
placeholder="请填写物料型号"/>
</div> </div>
</div> </div>
@ -92,6 +95,10 @@
function changeUnit() { function changeUnit() {
} }
function bindTableToolbarFunction() {
}
layui.use(['form', 'table', 'upload'], function () { layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery, var $ = layui.jquery,
form = layui.form, form = layui.form,
@ -197,7 +204,7 @@
}); });
bindTableToolbarFunction();
} }
}); });
@ -247,7 +254,7 @@
if (data.code !== '') { if (data.code !== '') {
req.mcode = data.code.trim(); req.mcode = data.code.trim();
} }
if(data.version !== ''){ if (data.version !== '') {
req.version = data.version.trim(); req.version = data.version.trim();
} }
//执行搜索重载 //执行搜索重载
@ -332,8 +339,8 @@
layer.full(index); layer.full(index);
}); });
return false; return false;
}else if (obj.event === 'downloadFile') { } else if (obj.event === 'downloadFile') {
window.open("/download/inventoryImportDownload","_self"); window.open("/download/inventoryImportDownload", "_self");
} }
}); });
@ -376,7 +383,7 @@
// 获取当前showQuantity 的长度 // 获取当前showQuantity 的长度
let length = Object.getOwnPropertyNames(showQuantity).length; let length = Object.getOwnPropertyNames(showQuantity).length;
if (length> 0) { if (length > 0) {
if (clickNum < length) { if (clickNum < length) {
@ -451,52 +458,55 @@
}; };
//用于导入数据 //用于导入数据
var upLoader = upload.render({ function bindTableToolbarFunction() {
elem: "#u_fileUpload", // 绑定元素 var upLoader = upload.render({
url: '/excel/importInventory', // 上传接口 elem: "#u_fileUpload", // 绑定元素
accept: 'file', // 允许上传的格式, url: '/excel/importInventory', // 上传接口
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。 accept: 'file', // 允许上传的格式,
layer.load(); //上传loading before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
}, layer.load(); //上传loading
exts: 'xls|xlsx|csv', },
done: function (res) { exts: 'xls|xlsx|csv',
layer.closeAll('loading'); //关闭loading done: function (res) {
//如果上传成功 layer.closeAll('loading'); //关闭loading
if (res.code === 200) { //如果上传成功
var re = ""; if (res.code === 200) {
for (let i = 0; i < res.data.errMsg.length; i++) { var re = "";
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>"; for (let i = 0; i < res.data.errMsg.length; i++) {
re += show var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
} re += show
for (let i = 0; i < res.data.dataList.length; i++) { }
var code = res.data.dataList[i]["code"] === null ? '' : res.data.dataList[i]["code"]; for (let i = 0; i < res.data.dataList.length; i++) {
var mname = res.data.dataList[i]["mname"]; var code = res.data.dataList[i]["code"] === null ? '' : res.data.dataList[i]["code"];
var version = res.data.dataList[i]["version"] === null ? '' : res.data.dataList[i]["version"]; var mname = res.data.dataList[i]["mname"];
var quantity = res.data.dataList[i]["quantity"]; var version = res.data.dataList[i]["version"] === null ? '' : res.data.dataList[i]["version"];
var show = "<p style='color: #00FF00'>" + code + ", " + mname + ", " + version + ", 数量为" + quantity + ":成功" + "</p>"; var quantity = res.data.dataList[i]["quantity"];
re += show var show = "<p style='color: #00FF00'>" + code + ", " + mname + ", " + version + ", 数量为" + quantity + ":成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
} }
layer.open({ },
type: 1, error: function () {
skin: 'layui-layer-rim', //加上边框 layer.closeAll('loading'); //关闭loading
area: ['500px', '500px'], //宽高 var demoText = $('#demoText');
content: re demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
}) })
} else {
layer.msg(res.msg)
} }
})
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
})
}); });
</script> </script>

106
src/main/resources/templates/pages/material/material-out.html

@ -104,6 +104,9 @@
</div> </div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script> <script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script> <script>
function bindTableToolbarFunction(){
}
layui.use(['form', 'table', 'upload'], function () { layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery, var $ = layui.jquery,
form = layui.form, form = layui.form,
@ -208,6 +211,7 @@
let col = {field: 'price', width: 150, title: '物料单价'}; let col = {field: 'price', width: 150, title: '物料单价'};
cols.splice(6,0,col); cols.splice(6,0,col);
table.reload('currentTableId',{cols:[cols]}); table.reload('currentTableId',{cols:[cols]});
bindTableToolbarFunction();
} }
} }
@ -217,6 +221,59 @@
}); });
//用于导入数据
function bindTableToolbarFunction() {
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMaterial', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
if (res.code === 200) {
for (let i = 0; i < res.data.dataList.length; i++) {
var mname = res.data.dataList[i]["mname"];
var code = res.data.dataList[i]["code"] == null || res.data.dataList[i]["code"] === undefined ? "" : res.data.dataList[i]["code"];
var version = res.data.dataList[i]["version"] == null || res.data.dataList[i]["version"] === undefined ? "" : res.data.dataList[i]["version"];
var texture = res.data.dataList[i]["texture"] == null || res.data.dataList[i]["texture"] === undefined ? "" : res.data.dataList[i]["texture"];
var unit = res.data.dataList[i]["unit"] == null || res.data.dataList[i]["unit"] === undefined ? "" : res.data.dataList[i]["unit"];
var typeId = res.data.dataList[i]["typeId"] == null || res.data.dataList[i]["typeId"] === undefined ? "" : res.data.dataList[i]["typeId"];
var show = "<p style='color: #00FF00'>" + mname + " " + version + " " + code + " " + texture + " " + unit + " " + typeId + " :成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
}
// 监听搜索操作 // 监听搜索操作
@ -362,56 +419,7 @@
} }
}); });
//用于导入数据
var upLoader = upload.render({
elem: "#u_fileUpload", // 绑定元素
url: '/excel/importExcelByMaterial', // 上传接口
accept: 'file', // 允许上传的格式,
before: function (obj) { //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
},
exts: 'xls|xlsx|csv',
done: function (res) {
layer.closeAll('loading'); //关闭loading
//如果上传成功
var re = "";
for (let i = 0; i < res.data.errMsg.length; i++) {
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
re += show
}
if (res.code === 200) {
for (let i = 0; i < res.data.dataList.length; i++) {
var mname = res.data.dataList[i]["mname"];
var code = res.data.dataList[i]["code"] == null || res.data.dataList[i]["code"] == undefined ? "" : res.data.dataList[i]["code"];
var version = res.data.dataList[i]["version"] == null || res.data.dataList[i]["version"] == undefined ? "" : res.data.dataList[i]["version"];
var texture = res.data.dataList[i]["texture"] == null || res.data.dataList[i]["texture"] == undefined ? "" : res.data.dataList[i]["texture"];
var unit = res.data.dataList[i]["unit"] == null || res.data.dataList[i]["unit"] == undefined ? "" : res.data.dataList[i]["unit"];
var typeId = res.data.dataList[i]["typeId"] == null || res.data.dataList[i]["typeId"] == undefined ? "" : res.data.dataList[i]["typeId"];
var show = "<p style='color: #00FF00'>" + mname + " " + version + " " + code + " " + texture + " " + unit + " " + typeId + " :成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
}
},
error: function () {
layer.closeAll('loading'); //关闭loading
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
//监听表格复选框选择 //监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) { table.on('checkbox(currentTableFilter)', function (obj) {

103
src/main/resources/templates/pages/materialtype/materialType_view.html

@ -59,8 +59,12 @@
<script type="text/html" id="toolbarDemo"> <script type="text/html" id="toolbarDemo">
<div class="layui-btn-container"> <div class="layui-btn-container">
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" th:style="'display:'+${display}"> 添加</button> <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete" th:style="'display:'+${display}"> 删除</button> th:style="'display:'+${display}"> 添加
</button>
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"
th:style="'display:'+${display}"> 删除
</button>
<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" id="u_fileUpload" <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" id="u_fileUpload"
lay-event="import">导入数据 lay-event="import">导入数据
</button> </button>
@ -73,8 +77,10 @@
<script type="text/html" id="currentTableBar"> <script type="text/html" id="currentTableBar">
<a class="layui-btn layui-btn-normal layui-btn-xs data-count-subclass" lay-event="subclass">子类型</a> <a class="layui-btn layui-btn-normal layui-btn-xs data-count-subclass" lay-event="subclass">子类型</a>
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="detail" th:style="'display:'+${display}">详情</a> <a class="layui-btn layui-btn-xs data-count-edit" lay-event="detail"
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" th:style="'display:'+${display}">删除</a> th:style="'display:'+${display}">详情</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete"
th:style="'display:'+${display}">删除</a>
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" th:style="'display:'+${display}" <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" th:style="'display:'+${display}"
lay-event="realDelete">彻底删除</a> lay-event="realDelete">彻底删除</a>
</script> </script>
@ -83,6 +89,9 @@
</div> </div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script> <script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script> <script>
function bindTableToolbarFunction(){
}
layui.use(['form', 'table', 'upload'], function () { layui.use(['form', 'table', 'upload'], function () {
var $ = layui.jquery, var $ = layui.jquery,
form = layui.form, form = layui.form,
@ -132,6 +141,7 @@
page: true, page: true,
skin: 'line', skin: 'line',
done: function () { done: function () {
bindTableToolbarFunction();
} }
}); });
@ -175,8 +185,7 @@
$(window).on("resize", function () { $(window).on("resize", function () {
layer.full(index); layer.full(index);
}); });
} } else if (obj.event === 'delete') { // 监听删除操作
else if (obj.event === 'delete') { // 监听删除操作
var checkStatus = table.checkStatus('currentTableId') var checkStatus = table.checkStatus('currentTableId')
, data = checkStatus.data; , data = checkStatus.data;
var req = {}; var req = {};
@ -221,55 +230,57 @@
layer.msg("未选中记录,请确认!"); layer.msg("未选中记录,请确认!");
return false; return false;
} }
} } else if (obj.event === 'downloadFile') {
else if (obj.event === 'downloadFile') { window.open("/download/materialTypeImportDownload", "_self");
window.open("/download/materialTypeImportDownload","_self");
} }
}); });
//用于导入数据 //用于导入数据
var upLoader = upload.render({ function bindTableToolbarFunction() {
elem: "#u_fileUpload", // 绑定元素 var upLoader = upload.render({
url: '/excel/importExcelByMT', // 上传接口 elem: "#u_fileUpload", // 绑定元素
accept: 'file', // 允许上传的格式, url: '/excel/importExcelByMT', // 上传接口
exts: 'xls|xlsx|csv', accept: 'file', // 允许上传的格式,
done: function (res) { exts: 'xls|xlsx|csv',
//如果上传成功 done: function (res) {
if (res.code == 200) { //如果上传成功
var re = ""; if (res.code == 200) {
for (let i = 0; i < res.data.errMsg.length; i++) { var re = "";
var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>"; for (let i = 0; i < res.data.errMsg.length; i++) {
re += show var show = "<p style='color: #ff211e'>" + res.data.errMsg[i] + ":错误" + "</p>";
} re += show
for (let i = 0; i < res.data.dataList.length; i++) { }
var tname = res.data.dataList[i]["tname"]; for (let i = 0; i < res.data.dataList.length; i++) {
var id = res.data.dataList[i]["oldId"]; var tname = res.data.dataList[i]["tname"];
var parentId = res.data.dataList[i]["parentId"] == null ? "" : res.data.dataList[i]["parentId"]; var id = res.data.dataList[i]["oldId"];
var introduce = res.data.dataList[i]["introduce"] == null ? "" : res.data.dataList[i]["introduce"]; var parentId = res.data.dataList[i]["parentId"] == null ? "" : res.data.dataList[i]["parentId"];
var show = "<p style='color: #00FF00'>" + tname + " " + id + " " + parentId + "成功" + "</p>"; var introduce = res.data.dataList[i]["introduce"] == null ? "" : res.data.dataList[i]["introduce"];
re += show var show = "<p style='color: #00FF00'>" + tname + " " + id + " " + parentId + "成功" + "</p>";
re += show
}
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['500px', '500px'], //宽高
content: re
})
} else {
layer.msg(res.msg)
} }
layer.open({ },
type: 1, error: function () {
skin: 'layui-layer-rim', //加上边框 var demoText = $('#demoText');
area: ['500px', '500px'], //宽高 demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
content: re demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
}) })
} else {
layer.msg(res.msg)
} }
});
}
},
error: function () {
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
upLoader.upload()
})
}
});
//监听表格复选框选择 //监听表格复选框选择
table.on('checkbox(currentTableFilter)', function (obj) { table.on('checkbox(currentTableFilter)', function (obj) {

BIN
target/classes/static/upload/materialImport.xlsx

Binary file not shown.
Loading…
Cancel
Save