Files
water-management-system/wm-production/src/main/resources/mapper/DispatchCommandMapper.xml
T
bot_dev2 6c6db59ba9 feat(wm-production): #69 调度指令管理完整实现
- 实体: DispatchCommand/DispatchExecution/DispatchTracking
- Mapper: MyBatis-Plus + XML (含台账分页/详情/统计)
- Service: 完整状态机 (draft→issued→received→executing→completed/rejected)
- Controller: /api/production/dispatch-command (全生命周期API)
- SQL DDL: 三表+索引
- 前端: CommandList/CommandDetail/CommandCreate (Vue3+TS+Element Plus)
- 单元测试: DispatchCommandServiceTest + DispatchTrackingServiceTest
2026-06-14 15:30:52 +08:00

45 lines
2.2 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.water.production.mapper.DispatchCommandMapper">
<select id="selectCommandPage" resultType="java.util.Map">
SELECT
c.id, c.command_no, c.command_title, c.command_type,
c.source, c.priority, c.status, c.issued_at, c.created_at,
COUNT(e.id) AS total_executions,
COUNT(CASE WHEN e.execute_status = 'completed' THEN 1 END) AS completed_count,
COUNT(CASE WHEN e.execute_status = 'rejected' THEN 1 END) AS rejected_count
FROM prod_dispatch_command c
LEFT JOIN prod_dispatch_execution e ON e.command_id = c.id AND e.deleted = 0
WHERE c.deleted = 0
<if test="status != null and status != ''">AND c.status = #{status}</if>
<if test="commandType != null and commandType != ''">AND c.command_type = #{commandType}</if>
<if test="keyword != null and keyword != ''">
AND (c.command_no LIKE '%' || #{keyword} || '%' OR c.command_title LIKE '%' || #{keyword} || '%')
</if>
<if test="startDate != null and startDate != ''">AND c.created_at &gt;= #{startDate}::timestamp</if>
<if test="endDate != null and endDate != ''">AND c.created_at &lt;= #{endDate}::timestamp</if>
GROUP BY c.id
ORDER BY c.created_at DESC
</select>
<select id="selectCommandDetail" resultType="java.util.Map">
SELECT c.*,
(SELECT json_agg(json_build_object(
'id', e.id, 'userId', e.user_id, 'userName', e.user_name,
'executeStatus', e.execute_status, 'receivedAt', e.received_at,
'feedback', e.feedback, 'completedAt', e.completed_at,
'rejectedReason', e.rejected_reason
)) FROM prod_dispatch_execution e WHERE e.command_id = c.id AND e.deleted = 0) AS executions
FROM prod_dispatch_command c
WHERE c.id = #{commandId} AND c.deleted = 0
</select>
<select id="selectStatusStats" resultType="java.util.Map">
SELECT status, COUNT(*) AS count
FROM prod_dispatch_command WHERE deleted = 0
GROUP BY status
</select>
</mapper>