Commit 987884a1 by zhangtw

入库导入新增按照material_id和areaId分组

库中不存在物料新增逻辑
parent d459a3be
...@@ -35,6 +35,7 @@ public class KeyDmBorrowServiceImpl { ...@@ -35,6 +35,7 @@ public class KeyDmBorrowServiceImpl {
private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog."; private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog.";
private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser."; private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser.";
private Map<String, String> userMap; private Map<String, String> userMap;
private String areaId;
// 把用户的id和名做成字典 // 把用户的id和名做成字典
@PostConstruct @PostConstruct
public void initUserMap() { public void initUserMap() {
...@@ -67,13 +68,12 @@ public class KeyDmBorrowServiceImpl { ...@@ -67,13 +68,12 @@ public class KeyDmBorrowServiceImpl {
public Page<Map<String, Object>> selectPendingList(Map<String, Object> map) { public Page<Map<String, Object>> selectPendingList(Map<String, Object> map) {
if (map == null) map = new HashMap<>(); if (map == null) map = new HashMap<>();
Map<String, Object> user = (Map<String, Object>) map.get("_user"); Map<String, Object> user = (Map<String, Object>) map.get("_user");
map.put("params", user);
// 获取应用机构代码
if (user != null) { if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user); Map<String, String> pos = DataScopeUtil.getPosition(user);
map.put("areaId", pos.get("area_id")); areaId = pos.get("area_id");
map.put("parentIds", user.get("parent_ids")+","+pos.get("area_id")); user.put("areaId", areaId);
} }
map.put("params", user);
return commonService.findPage(namespace + "selectPendingList", map); return commonService.findPage(namespace + "selectPendingList", map);
} }
......
...@@ -50,7 +50,7 @@ public class KeyDmInboundServiceImpl { ...@@ -50,7 +50,7 @@ public class KeyDmInboundServiceImpl {
private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog."; private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog.";
private final String borrowNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrow."; private final String borrowNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmBorrow.";
private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser."; private final String userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser.";
private String areaId;
private Map<String, String> userMap; private Map<String, String> userMap;
// 把用户的id和名做成字典 // 把用户的id和名做成字典
@PostConstruct @PostConstruct
...@@ -162,7 +162,14 @@ public class KeyDmInboundServiceImpl { ...@@ -162,7 +162,14 @@ public class KeyDmInboundServiceImpl {
int aff = commonService.update(namespace + "doInbound", map); int aff = commonService.update(namespace + "doInbound", map);
if (aff < 0) throw new CustomException("入库失败"); if (aff < 0) throw new CustomException("入库失败");
Map<String, Object> ret = getById(map); Map<String, Object> ret = getById(map);
ret.put("_user", map.get("_user")); Map<String, Object> user = (Map<String, Object>) map.get("_user");
if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user);
areaId = pos.get("area_id");
user.put("areaId", areaId);
}
ret.put("_user",user);
// 更新库存明细:调用 mapper 更新库存和日志(mapper 内实现或逐条处理) // 更新库存明细:调用 mapper 更新库存和日志(mapper 内实现或逐条处理)
commonService.update(namespace + "updateInventoryByInbound", ret); commonService.update(namespace + "updateInventoryByInbound", ret);
......
...@@ -43,6 +43,7 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> { ...@@ -43,6 +43,7 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> {
if (user != null) { if (user != null) {
Map<String, String> pos = DataScopeUtil.getPosition(user); Map<String, String> pos = DataScopeUtil.getPosition(user);
areaId = pos.get("area_id"); areaId = pos.get("area_id");
user.put("areaId", areaId);
} }
// 初始化日期格式 // 初始化日期格式
dateFormat.setLenient(false); dateFormat.setLenient(false);
...@@ -291,33 +292,32 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> { ...@@ -291,33 +292,32 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> {
try { try {
// 按物料ID分组汇总数量 // 按物料ID分组汇总数量
Map<String, BigDecimal> materialQuantityMap = new HashMap<>(); Map<String, Map<String, Object>> materialQuantityMap = new HashMap<>();
for (Map<String, Object> detail : inboundDetails) { for (Map<String, Object> detail : inboundDetails) {
String materialId = (String) detail.get("material_id"); String materialId = (String) detail.get("material_id");
BigDecimal quantity = (BigDecimal) detail.get("inbound_quantity");
if (materialId != null && quantity != null) { if (materialId != null) {
materialQuantityMap.merge(materialId, quantity, BigDecimal::add); if (materialQuantityMap.get(materialId) == null) {
materialQuantityMap.put(materialId, detail);
}else{
Map<String, Object> tempMap = new HashMap<>();
tempMap = materialQuantityMap.get(materialId);
int materialQuantity = (int) tempMap.get("inbound_quantity");
materialQuantity += (int) detail.get("inbound_quantity");
detail.put("inbound_quantity", materialQuantity);
materialQuantityMap.put(materialId, detail);
}
} }
} }
// 批量更新 // 批量更新
List<Map<String, Object>> updateList = new ArrayList<>(); List<Map<String, Object>> updateList = new ArrayList<>(materialQuantityMap.values());
for (Map.Entry<String, BigDecimal> entry : materialQuantityMap.entrySet()) {
Map<String, Object> updateParam = new HashMap<>();
updateParam.put("material_id", entry.getKey());
updateParam.put("quantity", entry.getValue());
updateParam.put("update_time", new Date());
updateParam.put("_user", user);
updateList.add(updateParam);
}
if (!updateList.isEmpty()) { if (!updateList.isEmpty()) {
Map<String, Object> batchParam = new HashMap<>(); Map<String, Object> batchParam = new HashMap<>();
batchParam.put("list", updateList); batchParam.put("list", updateList);
batchParam.put("_user", user); batchParam.put("_user", user);
batchParam.put("areaId", areaId);
commonService.update(namespace + "batchUpdateMaterialStock", batchParam); commonService.update(namespace + "batchUpdateMaterialStock", batchParam);
} }
...@@ -395,31 +395,29 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> { ...@@ -395,31 +395,29 @@ public class InboundFileListener extends AnalysisEventListener<InboundImp> {
detail.put("inbound_type", 1); detail.put("inbound_type", 1);
detail.put("is_used", 1); detail.put("is_used", 1);
// 转换入库数量 // 转换入库数量
BigDecimal inboundQuantity = BigDecimal.ZERO; Integer inboundQuantity = 0;
try { try {
if (StringUtils.isNotEmpty(data.getInbound_quantity())) { if (StringUtils.isNotEmpty(data.getInbound_quantity())) {
inboundQuantity = new BigDecimal(data.getInbound_quantity().trim()); inboundQuantity = Integer.parseInt(data.getInbound_quantity().trim());
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("数量格式转换失败: {}", data.getInbound_quantity()); log.warn("数量格式转换失败: {}", data.getInbound_quantity());
inboundQuantity = BigDecimal.ZERO;
} }
detail.put("inbound_quantity", inboundQuantity); detail.put("inbound_quantity", inboundQuantity);
// 转换单价 // 转换单价
BigDecimal unitPrice = BigDecimal.ZERO; Double unitPrice = 0.0;
try { try {
if (StringUtils.isNotEmpty(data.getUnit_price())) { if (StringUtils.isNotEmpty(data.getUnit_price())) {
unitPrice = new BigDecimal(data.getUnit_price().trim()); unitPrice = Double.parseDouble(data.getUnit_price().trim());
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("单价格式转换失败: {}", data.getUnit_price()); log.warn("单价格式转换失败: {}", data.getUnit_price());
unitPrice = BigDecimal.ZERO;
} }
detail.put("unit_price", unitPrice); detail.put("unit_price", unitPrice);
// 计算总金额 // 计算总金额
BigDecimal totalAmount = inboundQuantity.multiply(unitPrice); Double totalAmount = inboundQuantity * unitPrice;
detail.put("total_amount", totalAmount); detail.put("total_amount", totalAmount);
// 处理生产日期 // 处理生产日期
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
is_used = 1 is_used = 1
AND approval_status = 1 AND approval_status = 1
and approver_id = #{params.params.id} and approver_id = #{params.params.id}
<if test="params.areaId != null and params.areaId != ''"> <if test="params.params.areaId != null">
AND apply_dep_code = #{params.areaId} AND apply_dep_code = #{params.params.areaId}
</if> </if>
</where> </where>
ORDER BY submit_time DESC ORDER BY submit_time DESC
......
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
#{item.material_code}, #{item.material_code},
#{item.material_name}, #{item.material_name},
#{item.inbound_quantity}, #{item.inbound_quantity},
#{item.available_quantity}, 0,
0, 0,
0, 0,
#{item.is_used}, #{item.is_used},
...@@ -142,8 +142,8 @@ ...@@ -142,8 +142,8 @@
NOW(), NOW(),
#{_user.id}, #{_user.id},
NOW(), NOW(),
#{item.order_no}, 0,
#{apply_dep_code} #{_user.areaId}
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
...@@ -275,21 +275,19 @@ ...@@ -275,21 +275,19 @@
) )
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdateMaterialStock" parameterType="map"> <insert id="batchUpdateMaterialStock" parameterType="map">
UPDATE jl_key_dm_inventory INSERT INTO jl_key_dm_inventory (id, material_id, material_code, material_name, total_quantity, available_quantity, borrowed_quantity, damaged_quantity, is_used, create_by, create_time, order_no, apply_dep_code)
SET total_quantity = total_quantity + CASE id VALUES
<foreach collection="list" item="item"> <foreach collection="list" item="item" separator=",">
WHEN #{item.material_id} THEN #{item.quantity} (UUID(), #{item.material_id}, #{item.material_code}, #{item.material_name}, #{item.inbound_quantity},0 ,0, 0, 1, #{_user.id}, NOW(),0, #{_user.areaId})
</foreach> </foreach>
ELSE 0 ON DUPLICATE KEY UPDATE
END, total_quantity = total_quantity + VALUES(total_quantity),
borrowed_quantity = borrowed_quantity + VALUES(borrowed_quantity),
damaged_quantity = damaged_quantity + VALUES(damaged_quantity),
update_by = #{_user.id},
update_time = NOW() update_time = NOW()
WHERE apply_dep_code = #{areaId} </insert>
AND id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.material_id}
</foreach>
</update>
<insert id="insertInboundMaster" parameterType="map"> <insert id="insertInboundMaster" parameterType="map">
INSERT INTO jl_key_dm_inbound_record ( INSERT INTO jl_key_dm_inbound_record (
id, id,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论