Commit 6f19a0ed by zhangtw

入库、申领、归还

parent c5829391
...@@ -5,12 +5,18 @@ import com.scpyun.base.core.annotation.Api; ...@@ -5,12 +5,18 @@ import com.scpyun.base.core.annotation.Api;
import com.scpyun.base.core.annotation.ApiOperation; import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.core.exception.CustomException; import com.scpyun.base.core.exception.CustomException;
import com.scpyun.base.db.service.CommonService; import com.scpyun.base.db.service.CommonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*; import java.util.*;
@Api("办公用品入库管理") @Api("办公用品入库管理")
...@@ -20,9 +26,34 @@ public class KeyDmInboundServiceImpl { ...@@ -20,9 +26,34 @@ public class KeyDmInboundServiceImpl {
private CommonService commonService; private CommonService commonService;
private static final String SUCCESS = "success"; private static final String SUCCESS = "success";
private static final int OP_TYPE_RETURN = 1; // 操作类型-归还
private static final String FIELD_ID = "id";
private static final String FIELD_INBOUND_ID = "inbound_id";
private static final String FIELD_DETAILS = "details";
private static final Logger log = LoggerFactory.getLogger(KeyDmInboundServiceImpl.class);
private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInbound."; private final String namespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInbound.";
private final String detailNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInboundDetail."; private final String detailNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmInboundDetail.";
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 userNamespace = "com.scpyun.platform.standard.jilinsscgsdp.keyDmUser.";
private Map<String, String> userMap;
@PostConstruct
public void initUserMap() {
List<Map<String,Object>> userList = commonService.findList(userNamespace + "getUserMap", null);
// 此时commonService已被注入,非null
userMap = new HashMap<>();
for (Map<String, Object> user : userList) {
String userId = String.valueOf(user.get("Id")); // 转为String,避免类型问题
String userName = (String) user.get("name");
if (userId != null && userName != null) { // 空值防御
userMap.put(userId, userName);
}
}
}
@ApiOperation(value = "入库记录列表", desc = "分页查询") @ApiOperation(value = "入库记录列表", desc = "分页查询")
public Page<Map<String, Object>> selectList(Map<String, Object> map) { public Page<Map<String, Object>> selectList(Map<String, Object> map) {
if (map == null) map = new HashMap<>(); if (map == null) map = new HashMap<>();
...@@ -38,10 +69,28 @@ public class KeyDmInboundServiceImpl { ...@@ -38,10 +69,28 @@ public class KeyDmInboundServiceImpl {
System.out.println(map); System.out.println(map);
map.put("id", UUID.randomUUID().toString()); map.put("id", UUID.randomUUID().toString());
map.put("order_no",0); map.put("order_no",0);
Instant instant = Instant.parse((String) map.get("inbound_date")); // 日期格式转换:兼容 2025-12-26 和 2025-12-25T16:00:00.000Z 两种格式
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); String dateStr = (String) map.get("inbound_date");
Date inbound_date = java.sql.Date.valueOf(localDate); Date inbound_date = null;
map.put("inbound_date",inbound_date); if (dateStr != null && !dateStr.trim().isEmpty()) {
try {
if (dateStr.contains("T") || dateStr.contains("Z")) {
// 处理带时区的ISO格式:转换为东八区日期
DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_INSTANT;
Instant instant = Instant.parse(dateStr);
// 转换为东八区的LocalDate
LocalDate localDate = instant.atZone(ZoneId.of("Asia/Shanghai")).toLocalDate();
inbound_date = java.sql.Date.valueOf(localDate);
} else {
// 处理纯日期格式(2025-12-26)
LocalDate localDate = LocalDate.parse(dateStr);
inbound_date = java.sql.Date.valueOf(localDate);
}
} catch (DateTimeParseException e) {
throw new CustomException("日期格式错误,支持格式:2025-12-26 或 2025-12-26T16:00:00.000Z");
}
}
map.put("inbound_date", inbound_date);
map.put("inbound_status",0); map.put("inbound_status",0);
if (commonService.insert(namespace + "insert", map) != 1) throw new CustomException("保存失败"); if (commonService.insert(namespace + "insert", map) != 1) throw new CustomException("保存失败");
...@@ -56,26 +105,29 @@ public class KeyDmInboundServiceImpl { ...@@ -56,26 +105,29 @@ public class KeyDmInboundServiceImpl {
} else { } else {
int aff = commonService.update(namespace + "update", map); int aff = commonService.update(namespace + "update", map);
if (aff < 0) throw new CustomException("保存失败"); if (aff < 0) throw new CustomException("保存失败");
commonService.delete(namespace + "deleteDetailsByInboundId", map); commonService.delete(detailNamespace + "deleteDetailsByInboundId", map);
if (details != null) { if (details != null) {
for (Map<String, Object> d : details) { for (Map<String, Object> d : details) {
d.put("id",UUID.randomUUID().toString()); d.put("id",UUID.randomUUID().toString());
d.put("inbound_id", map.get("id")); d.put("inbound_id", map.get("id"));
d.put("inbound_type", map.get("inbound_type"));
commonService.insert(detailNamespace + "insertDetail", d); commonService.insert(detailNamespace + "insertDetail", d);
} }
} }
} }
return SUCCESS; return SUCCESS;
} }
// 删除入库单以及明细
@Transactional(rollbackFor = Exception.class)
@ApiOperation(value = "删除入库单", desc = "逻辑删除") @ApiOperation(value = "删除入库单", desc = "逻辑删除")
public String delete(Map<String, Object> map) { public String delete(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失"); if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
int aff = commonService.update(namespace + "delete", map); int aff = commonService.update(namespace + "delete", map);
if (aff < 0) throw new CustomException("删除失败"); int detail_aff = commonService.update(detailNamespace + "deleteDetailsByInboundId", map);
if (aff < 0 || detail_aff < 0) throw new CustomException("删除失败");
return SUCCESS; return SUCCESS;
} }
@Transactional(rollbackFor = Exception.class)
@ApiOperation(value = "执行入库", desc = "将入库单置为已入库,更新库存并写日志") @ApiOperation(value = "执行入库", desc = "将入库单置为已入库,更新库存并写日志")
public String doInbound(Map<String, Object> map) { public String doInbound(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失"); if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
...@@ -88,7 +140,7 @@ public class KeyDmInboundServiceImpl { ...@@ -88,7 +140,7 @@ public class KeyDmInboundServiceImpl {
commonService.update(namespace + "updateInventoryByInbound", ret); commonService.update(namespace + "updateInventoryByInbound", ret);
commonService.insert(materialNamespace + "insertLog", ret); commonService.insert(materialNamespace + "insertLogByInbound", ret);
return SUCCESS; return SUCCESS;
} }
...@@ -98,16 +150,116 @@ public class KeyDmInboundServiceImpl { ...@@ -98,16 +150,116 @@ public class KeyDmInboundServiceImpl {
return commonService.findPage(namespace + "selectPendingReturnList", map); return commonService.findPage(namespace + "selectPendingReturnList", map);
} }
/**
* 处理物资归还
* 核心逻辑:生成入库单 → 更新申领明细归还数量 → 更新库存 → 记录操作日志
*
* @param paramMap 入参Map,必须包含id(申领单ID)
* @return 处理结果(success/fail)
* @throws CustomException 业务异常
*/
@Transactional(rollbackFor = Exception.class)
@ApiOperation(value = "处理归还", desc = "基于申领生成入库单并更新库存") @ApiOperation(value = "处理归还", desc = "基于申领生成入库单并更新库存")
public String processReturn(Map<String, Object> map) { public String processReturn(Map<String, Object> paramMap) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失"); // 1. 入参校验(增强版:多层级空值防御)
// 生成入库单 validateParam(paramMap);
commonService.insert(namespace + "insertInboundByReturn", map);
// 更新库存 try {
commonService.update(namespace + "updateInventoryByReturn", map); // 2. 获取待归还数据
// 写日志 Map<String, Object> returnData = getPendingReturnById(paramMap);
commonService.insert(namespace + "insertMaterialLogByReturn", map); log.info("开始处理物资归还,申领单ID:{}", paramMap.get(FIELD_ID));
// 3. 生成入库单ID并插入入库主表/明细表
generateInboundOrder(returnData);
// 4. 处理明细:更新归还数量、库存
processReturnDetails(returnData);
// 5. 记录物资操作日志
recordMaterialReturnLog(returnData);
log.info("物资归还处理完成,申领单ID:{},入库单ID:{}",
paramMap.get(FIELD_ID), returnData.get(FIELD_INBOUND_ID));
return SUCCESS; return SUCCESS;
} catch (CustomException e) {
log.error("处理物资归还业务异常,申领单ID:{},异常信息:{}",
paramMap.get(FIELD_ID), e.getMessage(), e);
throw e; // 抛出业务异常,触发事务回滚
} catch (Exception e) {
log.error("处理物资归还系统异常,申领单ID:{},异常信息:{}",
paramMap.get(FIELD_ID), e.getMessage(), e);
throw new CustomException("归还处理失败:" + e.getMessage()); // 包装为业务异常
}
}
/**
* 入参校验:确保核心参数非空
*/
private void validateParam(Map<String, Object> paramMap) {
if (paramMap == null || paramMap.get(FIELD_ID) == null) {
log.error("处理物资归还失败:入参缺失,paramMap={}", paramMap);
throw new CustomException("参数缺失:申领单ID(id)不能为空");
}
}
/**
* 生成入库单(主表+明细表)
*/
private void generateInboundOrder(Map<String, Object> returnData) {
// 生成唯一入库单ID
String inboundId = UUID.randomUUID().toString();
returnData.put(FIELD_INBOUND_ID, inboundId);
// 插入入库主表
commonService.insert(namespace + "insertInboundByReturn", returnData);
log.debug("插入入库主表成功,入库单ID:{}", inboundId);
// 插入入库明细表
commonService.insert(namespace + "insertInboundDetailByReturn", returnData);
log.debug("插入入库明细表成功,入库单ID:{}", inboundId);
}
/**
* 处理归还明细:更新申领明细归还数量、更新库存
*/
@SuppressWarnings("unchecked")
private void processReturnDetails(Map<String, Object> returnData) {
// 安全获取明细列表(避免类型转换异常)
List<Map<String, Object>> detailList = (List<Map<String, Object>>) returnData.get(FIELD_DETAILS);
if (detailList == null || detailList.isEmpty()) {
log.warn("申领单ID:{} 无归还明细数据,跳过库存更新", returnData.get(FIELD_ID));
return;
}
String applicationId = String.valueOf(returnData.get(FIELD_ID));
for (Map<String, Object> detail : detailList) {
// 填充申领单ID
detail.put("application_id", applicationId);
detail.put("op_type", OP_TYPE_RETURN);
detail.put("_user", returnData.get("_user"));
// 更新申领明细归还数量
commonService.insert(namespace + "updateBorrowDetailReturnedQuantity", detail);
// 更新库存(借出数量扣减)
commonService.update(namespace + "updateInventoryBorrowed", detail);
log.debug("更新库存成功,物资明细:{}", detail);
}
}
/**
* 记录物资归还操作日志
*/
private void recordMaterialReturnLog(Map<String, Object> returnData) {
try {
returnData.put("inbound_type", 1);
commonService.insert(materialNamespace + "insertLogByReturn", returnData);
log.debug("记录物资归还日志成功,申领单ID:{}", returnData.get(FIELD_ID));
} catch (Exception e) {
log.error("记录物资归还日志失败,申领单ID:{}", returnData.get(FIELD_ID), e);
// 日志记录失败是否抛异常?根据业务决策:若日志非核心,可捕获不抛;若核心则抛出
// throw new CustomException("日志记录失败:" + e.getMessage());
}
} }
@ApiOperation(value = "库存查询", desc = "实时库存") @ApiOperation(value = "库存查询", desc = "实时库存")
...@@ -126,6 +278,19 @@ public class KeyDmInboundServiceImpl { ...@@ -126,6 +278,19 @@ public class KeyDmInboundServiceImpl {
ret.put("details", details == null ? new java.util.ArrayList<>() : details); ret.put("details", details == null ? new java.util.ArrayList<>() : details);
List<Map<String, Object>> logs = commonService.findList(namespace + "selectLogsByInboundId", map); List<Map<String, Object>> logs = commonService.findList(namespace + "selectLogsByInboundId", map);
ret.put("logs", logs == null ? new java.util.ArrayList<>() : logs); ret.put("logs", logs == null ? new java.util.ArrayList<>() : logs);
initUserMap();
ret.put("userName", userMap.get(ret.get("create_by")));
return ret;
}
@ApiOperation(value = "归还详情", desc = "查询入库/归还详情及日志")
public Map<String, Object> getPendingReturnById(Map<String, Object> map) {
if (map == null || map.get("id") == null) throw new CustomException("参数缺失");
Map<String, Object> ret = new HashMap<>();
Map<String, Object> rec = commonService.getObject(borrowNamespace + "getById", map);
ret.putAll(rec == null ? new HashMap<>() : rec);
List<Map<String, Object>> details = commonService.findList(namespace+ "selectPendingReturnDetailsByApplicationId", map);
ret.put("details", details == null ? new java.util.ArrayList<>() : details);
return ret; return ret;
} }
} }
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
id,application_no,applicant_id,applicant_name,department_id,department_name,borrow_purpose,expected_return_date, id,application_no,applicant_id,applicant_name,department_id,department_name,borrow_purpose,expected_return_date,
approval_status,issue_status,is_used,create_by,create_time,order_no approval_status,issue_status,is_used,create_by,create_time,order_no
) VALUES ( ) VALUES (
#{id},#{application_no},#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date}, #{id},CONCAT('borrow', REPLACE(UUID(),'-','')),#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date},
#{approval_status},#{issue_status},1,#{_user.id},NOW(),#{order_no} #{approval_status},#{issue_status},1,#{_user.id},NOW(),#{order_no}
) )
</insert> </insert>
...@@ -94,6 +94,16 @@ ...@@ -94,6 +94,16 @@
FROM jl_key_dm_borrow_application WHERE id = #{id} FROM jl_key_dm_borrow_application WHERE id = #{id}
</insert> </insert>
<!-- 生成出库记录与明细(批量由 mapper 内部实现) -->
<insert id="insertOutboundDetail" parameterType="map">
<!-- mapper implementation should insert outbound record and details based on application id -->
INSERT INTO jl_key_dm_outbound_detail(id,outbound_id,material_id,outbound_type,outbound_quantity,unit_price,total_amount,borrow_application_detail_id,is_used,create_by,create_time)
SELECT UUID(), CONCAT('OUT', REPLACE(UUID(),'-','')),bad.material_id,2,bad.apply_quantity,m.unit_price,(m.unit_price * bad.apply_quantity) as total_amount,bad.id,1,#{_user.id},NOW()
FROM jl_key_dm_borrow_application_detail as bad
left join jl_key_dm_material as m on m.id = bad.material_id
WHERE application_id = #{id}
</insert>
<select id="selectInventoryByMaterialId" parameterType="map" resultType="map"> <select id="selectInventoryByMaterialId" parameterType="map" resultType="map">
select i.*,m.can_borrow select i.*,m.can_borrow
from jl_key_dm_inventory as i from jl_key_dm_inventory as i
...@@ -121,11 +131,7 @@ ...@@ -121,11 +131,7 @@
where material_id = #{material_id} where material_id = #{material_id}
</update> </update>
<!-- 插入日志 -->
<insert id="insertMaterialLogByApplication" parameterType="map">
<!-- 简化:实现者可在业务层调用单条插入,此处为占位 -->
insert into jl_key_dm_material_log()
</insert>
<select id="selectLogsByApplicationId" parameterType="map"> <select id="selectLogsByApplicationId" parameterType="map">
</select> </select>
......
...@@ -19,10 +19,13 @@ ...@@ -19,10 +19,13 @@
WHERE i.inbound_id = #{id} AND i.is_used = 1 ORDER BY i.create_time ASC WHERE i.inbound_id = #{id} AND i.is_used = 1 ORDER BY i.create_time ASC
</select> </select>
<delete id="deleteDetailsByInboundId" parameterType="map"> <!-- <delete id="deleteDetailsByInboundId" parameterType="map">-->
DELETE FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id} <!-- DELETE FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id}-->
</delete> <!-- </delete>-->
<update id="deleteDetailsByInboundId" parameterType="map">
UPDATE jl_key_dm_inbound_detail SET is_used = 0, update_by = #{_user.id}, update_time = NOW() WHERE inbound_id = #{id}
</update>
</mapper> </mapper>
...@@ -6,11 +6,23 @@ ...@@ -6,11 +6,23 @@
SELECT * FROM jl_key_dm_inbound_record SELECT * FROM jl_key_dm_inbound_record
<where> <where>
AND is_used = 1 AND is_used = 1
<if test="params.inbound_no != null and params.inbound_no != ''"> <if test="params.params.inbound_no != null">
AND (inbound_no LIKE CONCAT('%', #{params.inbound_no}, '%') OR batch_no LIKE CONCAT('%', #{params.inbound_no}, '%')) AND inbound_no LIKE CONCAT('%', #{params.params.inbound_no}, '%')
</if>
<if test="params.params.batch_no != null">
AND batch_no LIKE CONCAT('%', #{params.params.batch_no}, '%')
</if>
<if test="params.params.startDate != null and params.params.endDate != null">
AND inbound_date &gt;= #{params.params.startDate} and inbound_date &lt;= #{params.params.endDate}
</if>
<if test="params.params.inbound_type != null">
AND inbound_type = #{params.params.inbound_type}
</if>
<if test="params.params.inbound_status != null">
AND inbound_status = #{params.params.inbound_status}
</if> </if>
</where> </where>
ORDER BY inbound_date DESC ORDER BY inbound_date DESC,create_time desc
</select> </select>
<select id="getById" parameterType="map" resultType="map"> <select id="getById" parameterType="map" resultType="map">
...@@ -44,19 +56,39 @@ ...@@ -44,19 +56,39 @@
SELECT * FROM jl_key_dm_inventory SELECT * FROM jl_key_dm_inventory
<where> <where>
AND is_used = 1 AND is_used = 1
<if test="params.material_name != null and params.material_name != ''"> <if test="params.params.material_name != null and params.params.material_name != ''">
AND (material_name LIKE CONCAT('%', #{params.material_name}, '%') OR material_code LIKE CONCAT('%', #{params.material_name}, '%')) AND (material_name LIKE CONCAT('%', #{params.params.material_name}, '%') OR material_code LIKE CONCAT('%', #{params.params.material_name}, '%'))
</if> </if>
</where> </where>
ORDER BY material_name ASC ORDER BY material_name ASC
</select> </select>
<!-- insert inbound by return (simplified) -->
<!-- 入库主表添加归还入库单 -->
<insert id="insertInboundByReturn" parameterType="map"> <insert id="insertInboundByReturn" parameterType="map">
INSERT INTO jl_key_dm_inbound_record(id,inbound_no,batch_no,inbound_date,inbound_type,storage_location,inbound_status,remark,is_used,create_by,create_time) INSERT INTO jl_key_dm_inbound_record(id,inbound_no,batch_no,inbound_date,inbound_type,storage_location,inbound_status,remark,is_used,create_by,create_time)
SELECT UUID(), CONCAT('INR', REPLACE(UUID(),'-','')), '', NOW(), 2, '', 1, '归还入库', 1, #{_user.id}, NOW() SELECT #{inbound_id}, CONCAT('INR', REPLACE(UUID(),'-','')), '', NOW(), 2, '', 1, '归还入库', 1, #{_user.id}, NOW()
FROM jl_key_dm_borrow_application WHERE id = #{id} FROM jl_key_dm_borrow_application WHERE id = #{id}
</insert> </insert>
<!-- 入库明细添加 -->
<insert id="insertInboundDetailByReturn" parameterType="map">
insert into jl_key_dm_inbound_detail(id,inbound_id,material_id,inbound_type,inbound_quantity,unit_price,total_amount,production_date,expiry_date,is_used,create_by,create_time)
select UUID(), #{inbound_id}, material_id,2,apply_quantity,0,0,null,null,1,#{_user.id},now()
from jl_key_dm_borrow_application_detail where application_id = #{id}
</insert>
<!-- 修改申领明细表归还数量-->
<update id="updateBorrowDetailReturnedQuantity" parameterType="map">
update jl_key_dm_borrow_application_detail
set returned_quantity = returned_quantity + #{apply_quantity},damaged_quantity = damaged_quantity + #{damaged_quantity}
,update_by = #{_user.id},update_time = NOW()
where application_id = #{application_id} and material_id = #{material_id}
</update>
<update id="updateInventoryBorrowed" parameterType="map">
update jl_key_dm_inventory
set borrowed_quantity = borrowed_quantity - #{apply_quantity}
,damaged_quantity = damaged_quantity + #{damaged_quantity}
where material_id = #{material_id}
</update>
<!-- update inventory by inbound (placeholder) --> <!-- update inventory by inbound (placeholder) -->
<insert id="updateInventoryByInbound" parameterType="map"> <insert id="updateInventoryByInbound" parameterType="map">
...@@ -87,8 +119,8 @@ ...@@ -87,8 +119,8 @@
#{item.material_name}, #{item.material_name},
#{item.inbound_quantity}, #{item.inbound_quantity},
#{item.available_quantity}, #{item.available_quantity},
#{item.borrowed_quantity}, 0,
#{item.damaged_quantity}, 0,
#{item.is_used}, #{item.is_used},
#{_user.id}, #{_user.id},
NOW(), NOW(),
...@@ -100,10 +132,10 @@ ...@@ -100,10 +132,10 @@
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
material_code = VALUES(material_code), material_code = VALUES(material_code),
material_name = VALUES(material_name), material_name = VALUES(material_name),
total_quantity = VALUES(total_quantity), total_quantity = total_quantity + VALUES(total_quantity),
available_quantity = VALUES(available_quantity), available_quantity = available_quantity + VALUES(available_quantity),
borrowed_quantity = VALUES(borrowed_quantity), borrowed_quantity = borrowed_quantity + VALUES(borrowed_quantity),
damaged_quantity = VALUES(damaged_quantity), damaged_quantity = damaged_quantity + VALUES(damaged_quantity),
is_used = VALUES(is_used), is_used = VALUES(is_used),
update_by = VALUES(update_by), update_by = VALUES(update_by),
update_time = NOW(), update_time = NOW(),
...@@ -118,6 +150,34 @@ ...@@ -118,6 +150,34 @@
WHERE ml.relation_id = #{id} AND ml.is_used = 1 ORDER BY ml.create_time ASC WHERE ml.relation_id = #{id} AND ml.is_used = 1 ORDER BY ml.create_time ASC
</select> </select>
<select id="selectPendingReturnList" parameterType="map" resultType="map">
select ba.id,ba.applicant_id,ba.application_no,ba.applicant_name,ba.department_id,
ba.department_name,ba.issue_status,ba.expected_return_date,ba.issue_time
from jl_key_dm_borrow_application as ba
left join jl_key_dm_borrow_application_detail as bad on bad.application_id = ba.id
left join jl_key_dm_material as m on bad.material_id = m.id
<where>
m.can_borrow = 1 and ba.issue_status = 1
and bad.returned_quantity + bad.damaged_quantity != bad.apply_quantity
<if test="params.params.applicant_name != null and params.params.applicant_name != ''">
and applicant_name = concat('%',#{params.params.applicant_name},'%')
</if>
<if test="params.params.application_no != null and params.params.application_no != ''">
and application_no = concat('%',#{params.params.application_no},'%')
</if>
</where>
group by ba.id
</select>
<select id="selectPendingReturnDetailsByApplicationId" parameterType="map" resultType="map">
select ba.expected_return_date,ba.issue_time,
bad.material_id,bad.material_code,bad.material_name,bad.apply_quantity,bad.returned_quantity,
bad.damaged_quantity,bad.return_remark,bad.is_overdue,bad.overdue_days
from jl_key_dm_borrow_application_detail as bad
left join jl_key_dm_material as m on bad.material_id = m.id
left join jl_key_dm_borrow_application as ba on bad.application_id = ba.id
where ba.id = #{id}
</select>
</mapper> </mapper>
...@@ -12,7 +12,26 @@ ...@@ -12,7 +12,26 @@
) )
</foreach> </foreach>
</insert> </insert>
<insert id="insertLogByInbound" 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
<foreach collection="details" item="item" separator=",">
(
UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{id},#{item.material_id},#{item.inbound_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
)
</foreach>
</insert>
<insert id="insertLogByReturn" 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
<foreach collection="details" item="item" separator=",">
(
UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{inbound_id},#{item.material_id},#{item.apply_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
)
</foreach>
</insert>
<select id="selectLogsByApplicationId" parameterType="map" resultType="map"> <select id="selectLogsByApplicationId" parameterType="map" resultType="map">
SELECT ml.*,m.material_name SELECT ml.*,m.material_name
FROM jl_key_dm_material_log as ml FROM jl_key_dm_material_log as ml
......
...@@ -247,6 +247,13 @@ ...@@ -247,6 +247,13 @@
ORDER BY o.grade, o.sort ORDER BY o.grade, o.sort
</select> </select>
<!-- 将用户id和name做成字典-->
<select id="getUserMap" resultType="map">
select Id,name
from jl_key_dm_user
where is_used = 1
</select>
</mapper> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论