Commit 3ef0c218 by zhangtw

入库、申领

parent dfbb9913
......@@ -65,12 +65,8 @@ public class KeyDmBorrowServiceImpl {
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
Date expected_return_date = java.sql.Date.valueOf(localDate);
map.put("expected_return_date",expected_return_date);
map.put("approval_status", 0);
map.put("issue_status", 0);
map.put("is_used", 1);
map.put("create_by", user.get("id"));
map.put("create_time", new Date());
map.put("order_no", 0);
System.out.println(map);
// insert application
......@@ -80,11 +76,6 @@ public class KeyDmBorrowServiceImpl {
for (Map<String, Object> d : details) {
d.put("id",UUID.randomUUID().toString());
d.put("application_id", map.get("id"));
d.put("material_id", "测试");
d.put("is_used", 1);
d.put("create_by", user.get("id"));
d.put("create_time", new Date());
d.put("order_no", 0);
commonService.insert( detailNamespace + "insertDetail", d);
}
}
......@@ -98,7 +89,7 @@ public class KeyDmBorrowServiceImpl {
if (details != null) {
for (Map<String, Object> d : details) {
d.put("application_id", map.get("id"));
commonService.insert(namespace + "insertDetail", d);
commonService.insert(detailNamespace + "insertDetail", d);
}
}
}
......
......@@ -8,9 +8,10 @@ import com.scpyun.base.db.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
@Api("办公用品入库管理")
@Service("keyDmInbound")
......@@ -20,7 +21,8 @@ public class KeyDmInboundServiceImpl {
private static final String SUCCESS = "success";
private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInbound.";
private final String detailNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInboundDetail.";
private final String materialNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmMaterialLog.";
@ApiOperation(value = "入库记录列表", desc = "分页查询")
public Page<Map<String, Object>> selectList(Map<String, Object> map) {
if (map == null) map = new HashMap<>();
......@@ -33,11 +35,22 @@ public class KeyDmInboundServiceImpl {
Object id = map.get("id");
List<Map<String, Object>> details = (List<Map<String, Object>>) map.get("details");
if (id == null || String.valueOf(id).trim().isEmpty()) {
System.out.println(map);
map.put("id", UUID.randomUUID().toString());
map.put("order_no",0);
Instant instant = Instant.parse((String) map.get("inbound_date"));
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
Date inbound_date = java.sql.Date.valueOf(localDate);
map.put("inbound_date",inbound_date);
map.put("inbound_status",0);
if (commonService.insert(namespace + "insert", map) != 1) throw new CustomException("保存失败");
if (details != null) {
for (Map<String, Object> d : details) {
d.put("inbound_id", map.get("id"));
commonService.insert(namespace + "insertDetail", d);
d.put("inbound_type", map.get("inbound_type"));
d.put("id",UUID.randomUUID().toString());
commonService.insert(detailNamespace + "insertDetail", d);
}
}
} else {
......@@ -46,8 +59,9 @@ public class KeyDmInboundServiceImpl {
commonService.delete(namespace + "deleteDetailsByInboundId", map);
if (details != null) {
for (Map<String, Object> d : details) {
d.put("id",UUID.randomUUID().toString());
d.put("inbound_id", map.get("id"));
commonService.insert(namespace + "insertDetail", d);
commonService.insert(detailNamespace + "insertDetail", d);
}
}
}
......@@ -68,9 +82,13 @@ public class KeyDmInboundServiceImpl {
// 设置入库状态
int aff = commonService.update(namespace + "doInbound", map);
if (aff < 0) throw new CustomException("入库失败");
Map<String, Object> ret = getById(map);
ret.put("_user", map.get("_user"));
// 更新库存明细:调用 mapper 更新库存和日志(mapper 内实现或逐条处理)
commonService.update(namespace + "updateInventoryByInbound", map);
commonService.insert(namespace + "insertMaterialLogByInbound", map);
commonService.update(namespace + "updateInventoryByInbound", ret);
commonService.insert(materialNamespace + "insertLog", ret);
return SUCCESS;
}
......@@ -104,7 +122,7 @@ public class KeyDmInboundServiceImpl {
Map<String, Object> ret = new HashMap<>();
Map<String, Object> rec = commonService.getObject(namespace + "getById", map);
ret.putAll(rec == null ? new HashMap<>() : rec);
List<Map<String, Object>> details = commonService.findList(namespace + "selectDetailsByInboundId", map);
List<Map<String, Object>> details = commonService.findList(detailNamespace+ "selectDetailsByInboundId", map);
ret.put("details", details == null ? new java.util.ArrayList<>() : details);
List<Map<String, Object>> logs = commonService.findList(namespace + "selectLogsByInboundId", map);
ret.put("logs", logs == null ? new java.util.ArrayList<>() : logs);
......
......@@ -98,6 +98,7 @@
<update id="updateInventoryByApplication" parameterType="map">
<!-- 简化:调用存储过程或在 mapper 中实现逐条更新 -->
<!-- 实际实现依赖于业务,留给 mapper/服务调用具体 SQL -->
update jl_key_dm_inventory set
</update>
<!-- 插入日志 -->
......
......@@ -11,7 +11,12 @@
</insert>
<select id="selectDetailsByInboundId" parameterType="map" resultType="map">
SELECT * FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id} AND is_used = 1 ORDER BY create_time ASC
SELECT i.*,
m.material_code, m.material_name, m.category_id
FROM jl_key_dm_inbound_detail as i
left join jl_key_dm_material as m
on i.material_id = m.id
WHERE i.inbound_id = #{id} AND i.is_used = 1 ORDER BY i.create_time ASC
</select>
<delete id="deleteDetailsByInboundId" parameterType="map">
......
......@@ -59,9 +59,56 @@
</insert>
<!-- update inventory by inbound (placeholder) -->
<update id="updateInventoryByInbound" parameterType="map">
<!-- mapper should iterate details and call KeyDmInventory.increaseAvailable -->
</update>
<insert id="updateInventoryByInbound" parameterType="map">
<!-- 库存UPSERT:material_id存在则更新可用量/总量,不存在则插入 -->
<!-- 批量库存UPSERT:支持多物料同时更新/插入 -->
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,
update_by,
update_time,
order_no
)
VALUES
<foreach collection="details" item="item" separator=",">
(
#{item.id},
#{item.material_id},
#{item.material_code},
#{item.material_name},
#{item.inbound_quantity},
#{item.available_quantity},
#{item.borrowed_quantity},
#{item.damaged_quantity},
#{item.is_used},
#{_user.id},
NOW(),
#{_user.id},
NOW(),
#{item.order_no}
)
</foreach>
ON DUPLICATE KEY UPDATE
material_code = VALUES(material_code),
material_name = VALUES(material_name),
total_quantity = VALUES(total_quantity),
available_quantity = VALUES(available_quantity),
borrowed_quantity = VALUES(borrowed_quantity),
damaged_quantity = VALUES(damaged_quantity),
is_used = VALUES(is_used),
update_by = VALUES(update_by),
update_time = NOW(),
order_no = VALUES(order_no);
</insert>
<select id="selectLogsByInboundId" parameterType="map" resultType="map">
SELECT * FROM jl_key_dm_material_log WHERE relation_id = #{id} AND is_used = 1 ORDER BY create_time ASC
......
......@@ -5,9 +5,12 @@
<insert id="insertLog" parameterType="map">
INSERT INTO jl_key_dm_material_log(
id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
) VALUES (
#{id},#{category_id},#{material_id},#{op_type},#{relation_id},#{relation_item_id},#{quantity},#{unit_price},#{total_amount},1,#{_user.id},NOW()
) VALUES
<foreach collection="details" item="item" separator=",">
(
UUID(),#{item.category_id},#{item.id},1,#{item.inbound_id},#{item.id},#{item.inbound_quantity},#{item.unit_price},#{item.total_amount},1,#{_user.id},NOW()
)
</foreach>
</insert>
<select id="selectLogsByApplicationId" parameterType="map" resultType="map">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论