Commit 8d1b21c2 by wangchunyang
parents 358760de cab7a9fc
...@@ -177,9 +177,9 @@ ...@@ -177,9 +177,9 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="200"> <el-table-column label="入库时间" align="center" prop="inboundDate" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span> <span>{{ parseTime(scope.row.createTime,'{y}-{m}-{d}') }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -903,7 +903,7 @@ export default { ...@@ -903,7 +903,7 @@ export default {
const queryForm = { const queryForm = {
pageNum: 1, pageNum: 1,
pageSize: 9999, pageSize: 9999,
orderId: row.orderId inboundOrderId: row.id
} }
const response = await listInbound_itemsAndMname(queryForm) const response = await listInbound_itemsAndMname(queryForm)
row.inboundOrderItemsList = response.rows.map(item => { row.inboundOrderItemsList = response.rows.map(item => {
...@@ -915,7 +915,8 @@ export default { ...@@ -915,7 +915,8 @@ export default {
ownerId: row.ownerId, ownerId: row.ownerId,
quantity: item.actualQuantity, quantity: item.actualQuantity,
unitWeight: item.unitWeight, unitWeight: item.unitWeight,
isUsed: 1 isUsed: 1,
unitPrice: item.unitPrice
}; };
}) })
// 第三步:确保数据存在后调用入库接口 // 第三步:确保数据存在后调用入库接口
......
package com.ruoyi.web.controller.inventory; package com.ruoyi.web.controller.inventory;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.core.domain.entity.Materials; import com.ruoyi.common.core.domain.entity.Materials;
import com.ruoyi.common.utils.uuid.UUID; import com.ruoyi.common.utils.uuid.UUID;
...@@ -11,6 +13,7 @@ import com.ruoyi.inventory.domain.vo.InboundMaterialTotalVO; ...@@ -11,6 +13,7 @@ import com.ruoyi.inventory.domain.vo.InboundMaterialTotalVO;
import com.ruoyi.inventory.domain.vo.InboundTemplateVO; import com.ruoyi.inventory.domain.vo.InboundTemplateVO;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
...@@ -127,13 +130,63 @@ public class InboundOrdersController extends BaseController ...@@ -127,13 +130,63 @@ public class InboundOrdersController extends BaseController
@RequestParam("updateSupport") Integer updateSupport, @RequestParam("updateSupport") Integer updateSupport,
@RequestParam(value = "orderType", required = false) Integer orderType) throws Exception @RequestParam(value = "orderType", required = false) Integer orderType) throws Exception
{ {
// 防护1:校验文件非空
if (file == null || file.isEmpty()) {
return error("导入文件不能为空!");
}
// 防护2:校验文件格式
String fileName = file.getOriginalFilename();
if (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls")) {
return error("仅支持Excel格式文件(.xlsx/.xls)!");
}
// 第二步:校验Excel列名是否匹配模板(核心!拦截非模板数据)
List<String> templateColumns = Arrays.asList(
"入库日期",
"SAP No",
"物料名称",
"TS Code",
"货主",
"批号",
"计划数量",
"单号",
"系统编号",
"件重",
"约数",
"实际件数",
"实发数量",
"仓库",
"库位",
"标签颜色",
"凭证号",
"单价",
"备注",
"订单类型",
"收货人",
"物料备注"
);
List<String> excelColumns = ExcelUtil.getExcelHeader(file.getInputStream()); // 自定义方法读取表头
if (CollectionUtils.isEmpty(excelColumns) || !excelColumns.containsAll(templateColumns)) {
return AjaxResult.error("导入文件不是标准模板!请下载官方模板后填写(缺失列:"
+ getMissingColumns(templateColumns, excelColumns) + ")");
}
ExcelUtil<InboundTemplateVO> util = new ExcelUtil<InboundTemplateVO>(InboundTemplateVO.class); ExcelUtil<InboundTemplateVO> util = new ExcelUtil<InboundTemplateVO>(InboundTemplateVO.class);
List<InboundTemplateVO> inboundOrders = util.importExcel(file.getInputStream()); List<InboundTemplateVO> inboundOrders = util.importExcel(file.getInputStream());
// 防护3:拦截空列表,避免 Service 层处理空数据
if (CollectionUtils.isEmpty(inboundOrders)) {
return error("Excel中未解析到有效数据,请检查模板是否正确!");
}
String operName = getUsername(); String operName = getUsername();
String message = inboundOrdersService.importInboundOrders(inboundOrders, updateSupport, operName, orderType); String message = inboundOrdersService.importInboundOrders(inboundOrders, updateSupport, operName, orderType);
return success(message); return success(message);
} }
// 辅助方法:获取缺失的列名
private String getMissingColumns(List<String> template, List<String> excel) {
return template.stream()
.filter(col -> !excel.contains(col))
.collect(Collectors.joining("、"));
}
/** /**
* 首页入库次数统计api * 首页入库次数统计api
......
...@@ -12,17 +12,9 @@ import java.math.BigDecimal; ...@@ -12,17 +12,9 @@ import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.RegExUtils;
...@@ -1909,4 +1901,34 @@ public class ExcelUtil<T> ...@@ -1909,4 +1901,34 @@ public class ExcelUtil<T>
} }
return method; return method;
} }
/**
* 读取Excel表头(第一行)
*/
public static List<String> getExcelHeader(InputStream inputStream) {
try (Workbook workbook = WorkbookFactory.create(inputStream)) {
Sheet sheet = workbook.getSheetAt(0);
Row headerRow = sheet.getRow(0); // 第一行是表头
if (headerRow == null) {
return Collections.emptyList();
}
return IntStream.range(0, headerRow.getLastCellNum())
.mapToObj(headerRow::getCell)
.map(cell -> {
// 单元格类型容错(数字/字符串统一转字符串)
if (cell == null) {
return "";
}
cell.setCellType(CellType.STRING);
return StringUtils.trim(cell.getStringCellValue());
})
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
} catch (Exception e) {
log.error("读取Excel表头失败", e);
return Collections.emptyList();
}
}
} }
...@@ -178,4 +178,6 @@ public class Inventory extends BaseEntity ...@@ -178,4 +178,6 @@ public class Inventory extends BaseEntity
/** 特殊存储要求 */ /** 特殊存储要求 */
// @Excel(name = "特殊存储要求") // @Excel(name = "特殊存储要求")
private String specialRequirements; private String specialRequirements;
private Double unitPrice;
} }
...@@ -93,6 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -93,6 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserCode != null and createUserCode != ''"> and create_user_code = #{createUserCode}</if> <if test="createUserCode != null and createUserCode != ''"> and create_user_code = #{createUserCode}</if>
<if test="updateUserCode != null and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if> <if test="updateUserCode != null and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if>
</where> </where>
order by inbound_date desc,create_time desc
</select> </select>
<select id="selectInboundOrdersById" parameterType="String" resultMap="InboundOrdersInboundOrderItemsResult"> <select id="selectInboundOrdersById" parameterType="String" resultMap="InboundOrdersInboundOrderItemsResult">
......
...@@ -459,7 +459,8 @@ and inventory_status = '1' ...@@ -459,7 +459,8 @@ and inventory_status = '1'
<if test="createUserCode != null">create_user_code,</if> <if test="createUserCode != null">create_user_code,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="updateUserCode != null">update_user_code,</if> <if test="updateUserCode != null">update_user_code,</if>
<if test="warehousesId != null"> warehouses_id,</if> <if test="warehousesId != null">warehouses_id,</if>
<if test="unitPrice != null"> unit_price,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
...@@ -486,6 +487,7 @@ and inventory_status = '1' ...@@ -486,6 +487,7 @@ and inventory_status = '1'
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="updateUserCode != null">#{updateUserCode},</if> <if test="updateUserCode != null">#{updateUserCode},</if>
<if test="warehousesId != null"> #{warehousesId},</if> <if test="warehousesId != null"> #{warehousesId},</if>
<if test="unitPrice != null"> #{unitPrice},</if>
</trim> </trim>
</insert> </insert>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论