Commit 66700587 by zhangtw

入库页面优化,导出功能优化

parent 563b3de0
......@@ -14,6 +14,7 @@ import com.alibaba.excel.exception.ExcelAnalysisException;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.UUID;
import javax.servlet.http.HttpServletResponse;
......@@ -24,6 +25,7 @@ import com.ruoyi.inventory.domain.vo.inboundVO.InboundTRDCTemplateVO;
import com.ruoyi.inventory.domain.vo.inboundVO.InboundTemplateVO;
import com.ruoyi.inventory.service.impl.InboundOrdersServiceImpl;
import com.ruoyi.system.service.ISysDictDataService;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -66,6 +68,10 @@ public class InboundOrdersController extends BaseController
List<InboundOrders> list = inboundOrdersService.selectInboundOrdersList(inboundOrders);
return getDataTable(list);
}
/**
* 获取字典映射表
*/
private Map<Object, Object> getDictMap(String dictType) {
List<SysDictData> dictList = iSysDictDataService.selectDictDataByType(dictType);
Map<Object, Object> dictMap = new HashMap<>();
......@@ -80,32 +86,74 @@ public class InboundOrdersController extends BaseController
@PreAuthorize("@ss.hasPermi('inventory:inbound:export')")
@Log(title = "入库单主", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, InboundOrders inboundOrders)
{
public void export(HttpServletResponse response, InboundOrders inboundOrders) {
// 1. 基础空值校验:查询结果为空时直接导出空表格,避免后续循环NPE
List<InboundItemsTO> list = inboundOrdersService.selectInboundOrdersAndItems(inboundOrders);
if (list == null || list.isEmpty()) {
ExcelUtil<InboundItemsTO> util = new ExcelUtil<>(InboundItemsTO.class);
// 替换 List.of() 为 Java 8 兼容的空列表创建方式
util.exportExcel(response, new ArrayList<>(), "入库单导出数据");
return;
}
// 2. 字典映射表空值校验:避免字典表为空导致的NPE
Map<Object, Object> colorDictMap = getDictMap("label_color");
colorDictMap = MapUtils.emptyIfNull(colorDictMap); // 空Map转为空集合,避免后续get操作NPE
// 3. 循环处理每条数据,增加全字段空值保护
for (InboundItemsTO inboundItem : list) {
if (inboundItem != null) {
inboundItem.setPackageWeight(inboundItem.getWeight() * (inboundItem.getActualQuantity() / inboundItem.getActualPackages()));
inboundItem.setUnitWeight(inboundItem.getWeight() * (inboundItem.getActualQuantity() / inboundItem.getActualPackages()));
inboundItem.setLabelColorName((String) colorDictMap.get(inboundItem.getLabelColor()+""));
switch (inboundItem.getOrderTypeId()) {
case "1":
inboundItem.setRelocation(inboundItem.getRemark());
break;
case "2":
inboundItem.setFinishedLocation(inboundItem.getRemark());
break;
case "3":
inboundItem.setRemarkTrdc(inboundItem.getRemark());
inboundItem.setFinishedSystemNo(inboundItem.getSystemNo());
inboundItem.setFinishedOrderId(inboundItem.getOrderId());
break;
}
// 跳过空对象
if (inboundItem == null) {
continue;
}
// ========== 3.1 数学运算安全处理(避免除零/空值运算NPE) ==========
// 初始化默认值,避免空值运算
Double weight = inboundItem.getWeight() == null ? 0.0 : inboundItem.getWeight();
Double actualQuantity = inboundItem.getActualQuantity() == null ? 0.0 : inboundItem.getActualQuantity();
Double actualPackages = inboundItem.getActualPackages() == null ? 1.0 : inboundItem.getActualPackages();
// 安全除法:避免除零异常
double quantityPerPackage = actualPackages == 0 ? 0 : actualQuantity / actualPackages;
// 计算重量(空值保护)
double packageWeight = weight * quantityPerPackage;
// 赋值(避免setter传入null)
inboundItem.setPackageWeight(packageWeight);
inboundItem.setUnitWeight(packageWeight); // 与packageWeight值相同
// ========== 3.2 标签颜色名称映射(空值保护) ==========
String labelColor = inboundItem.getLabelColor() == null ? "" : inboundItem.getLabelColor().toString();
String labelColorName = (String) colorDictMap.get(labelColor);
inboundItem.setLabelColorName(StringUtils.defaultIfBlank(labelColorName, "")); // 空值转为空字符串
// ========== 3.3 订单类型分支处理(空值保护) ==========
String orderTypeId = StringUtils.defaultIfBlank(inboundItem.getOrderTypeId(), "-");
String remark = StringUtils.defaultIfBlank(inboundItem.getRemark(), "-");
String systemNo = StringUtils.defaultIfBlank(inboundItem.getSystemNo(), "-");
String orderId = StringUtils.defaultIfBlank(inboundItem.getOrderId(), "-");
switch (orderTypeId) {
case "1":
inboundItem.setRelocation(remark);
break;
case "2":
inboundItem.setFinishedLocation(remark);
break;
case "3":
inboundItem.setRemarkTrdc(remark);
inboundItem.setFinishedSystemNo(systemNo);
inboundItem.setFinishedOrderId(orderId);
break;
// 增加默认分支,避免未匹配的情况
default:
// 可选:记录日志或设置默认值
break;
}
}
ExcelUtil<InboundItemsTO> util = new ExcelUtil<InboundItemsTO>(InboundItemsTO.class);
// 4. 导出Excel(最终兜底:确保传入非null列表)
ExcelUtil<InboundItemsTO> util = new ExcelUtil<>(InboundItemsTO.class);
util.exportExcel(response, list, "入库单导出数据");
}
......
......@@ -100,7 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserCode != null and createUserCode != ''"> and create_user_code = #{createUserCode}</if>
<if test="updateUserCode != null and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if>
</where>
order by date(inbound_date) desc,create_time desc
order by order_status asc, date(inbound_date) desc,create_time desc
</select>
<select id="selectInboundOrdersById" parameterType="String" resultMap="InboundOrdersInboundOrderItemsResult">
......@@ -334,10 +334,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ioi.label_color, ioi.voucher_number, m.storage_temperature,
m.hazard_id, io.order_id, io.system_no, io.owner_id,
ioi.label_quantity, io.order_type, io.order_type_id, ioi.remark
from materials as m
inner join inbound_order_items as ioi on ioi.material_id = m.id
inner join inbound_orders as io on ioi.inbound_order_id = io.id
inner join storage_locations as sl on ioi.location_id = sl.id
from inbound_order_items as ioi
left join materials as m on ioi.material_id = m.id
left join inbound_orders as io on ioi.inbound_order_id = io.id
left join storage_locations as sl on ioi.location_id = sl.id
order by order_status asc, date(io.inbound_date) desc, io.create_time desc
</select>
<resultMap id="InboundOrderAndItemsMap" type="com.ruoyi.inventory.domain.TO.InboundItemsTO">
<!-- 基础字段映射:SQL字段名 -> Java实体类字段名 -->
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论