mitao
5 天以前 1093b185322515aebcccee208018346e7f9edbb3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?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.ruoyi.system.mapper.AssetInventoryTaskMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.AssetInventoryTask">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="dept_id" property="deptId" />
        <result column="task_name" property="taskName" />
        <result column="execute_date" property="executeDate" />
        <result column="status" property="status" />
        <result column="remarks" property="remarks" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="disabled" property="disabled" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, dept_id, task_name, execute_date, status, remarks, create_time, create_by, update_time, update_by, disabled
    </sql>
 
    <!-- 获取盘点任务详情中的资产列表 -->
    <select id="getAssetMainInventoryList" resultType="com.ruoyi.system.vo.asset.AssetMainInventoryVO">
        SELECT
            am.id,
            am.asset_code,
            am.asset_name,
            at2.type_name AS asset_type_name,
            at1.type_name AS parent_asset_type,
            am.specification_model,
            am.category,
            am.measurement_unit,
            am.quantity,
            am.unit_price,
            am.total_value,
            am.accounting_voucher_no,
            am.accounting_subject,
            am.accounting_status,
            am.accounting_amount,
            am.accounting_date,
            am.asset_status,
            td.dept_name AS ownership_dept_name,
            am.ownership_dept_id,
            am.asset_type_id,
            am.address_type,
            am.address,
            am.use_dept_id,
            am.warehouse_id,
            am.user_name,
            aw.warehouse_name,
            td2.dept_name AS use_dept_name,
            su.nick_name AS check_user_name,
            aiti.result_status AS inventory_status,
            aiti.real_dept_name,
            aiti.real_user_name,
            aiti.id AS asset_inventory_task_item_id,
            aiti.exception_explain
        FROM
            asset_inventory_task_item aiti
        INNER JOIN
            asset_main am ON aiti.asset_main_id = am.id
        LEFT JOIN
            asset_type at2 ON am.asset_type_id = at2.id
        LEFT JOIN
            asset_type at1 ON at1.id = (CASE WHEN at2.level = 2 THEN at2.parent_id ELSE at2.id END)
        LEFT JOIN
            t_dept td ON am.ownership_dept_id = td.id
        LEFT JOIN
            sys_user su ON aiti.user_id = su.user_id
        LEFT JOIN
            t_dept td2 ON am.address_type = 0 AND am.use_dept_id = td2.id
        LEFT JOIN
            asset_warehouse aw ON am.address_type = 1 AND am.warehouse_id = aw.id
        WHERE
            aiti.inventory_task_id = #{taskId}
        ORDER BY
            am.asset_code
    </select>
 
    <!-- 获取盘点任务中的所有盘点人姓名(去重) -->
    <select id="getInventoryUserNames" resultType="java.lang.String">
        SELECT DISTINCT su.nick_name
        FROM
            asset_inventory_task_item aiti
        INNER JOIN
            sys_user su ON aiti.user_id = su.user_id
        WHERE
            aiti.inventory_task_id = #{taskId}
            AND su.nick_name IS NOT NULL
            AND su.nick_name != ''
        ORDER BY
            su.nick_name
    </select>
    <select id="getAssetMainInventoryPageList" resultType="com.ruoyi.system.vo.asset.AssetMainInventoryVO">
 
        SELECT
        am.id,
        am.asset_code,
        am.asset_name,
        at.type_name AS asset_type_name,
        am.specification_model,
        am.category,
        am.measurement_unit,
        am.quantity,
        am.unit_price,
        am.total_value,
        am.accounting_voucher_no,
        am.accounting_subject,
        am.accounting_status,
        am.accounting_amount,
        am.accounting_date,
        am.asset_status,
        td.dept_name AS ownership_dept_name,
        am.ownership_dept_id,
        am.asset_type_id,
        am.address_type,
        am.address,
        am.use_dept_id,
        am.warehouse_id,
        am.user_name,
        aw.warehouse_name,
        td2.dept_name AS use_dept_name,
        su.nick_name AS check_user_name,
        aiti.result_status AS inventory_status,
        aiti.real_dept_name,
        aiti.real_user_name,
        aiti.id AS asset_inventory_task_item_id,
        aiti.exception_explain
        FROM
        asset_inventory_task_item aiti
        INNER JOIN
        asset_main am ON aiti.asset_main_id = am.id
        LEFT JOIN
        asset_type at ON am.asset_type_id = at.id
        LEFT JOIN
        t_dept td ON am.ownership_dept_id = td.id
        LEFT JOIN
        sys_user su ON aiti.user_id = su.user_id
        LEFT JOIN
            t_dept td2 ON am.address_type = 0 AND am.use_dept_id = td2.id
        LEFT JOIN
            asset_warehouse aw ON am.address_type = 1 AND am.warehouse_id = aw.id
        <where>
            aiti.inventory_task_id = #{query.id}
            <if test="query.keyword != null and query.keyword != ''">
                AND (am.asset_name LIKE CONCAT('%',#{query.keyword},'%') OR
                am.asset_code LIKE CONCAT('%',#{query.keyword},'%'))
            </if>
            <if test="query.resultStatus != null">
                AND aiti.result_status = #{query.reslutStatus}
            </if>
        </where>
        ORDER BY
            am.asset_code
    </select>
 
    <!-- 获取盘点任务统计数据 -->
    <select id="getInventoryTaskStatistics" resultType="com.ruoyi.system.vo.asset.InventoryTaskStatisticsVO">
        SELECT
            COALESCE(SUM(CASE WHEN result_status = 0 THEN 1 ELSE 0 END), 0) as pendingCount,
            COALESCE(SUM(CASE WHEN result_status = 1 THEN 1 ELSE 0 END), 0) as normalCount,
            COALESCE(SUM(CASE WHEN result_status = 2 THEN 1 ELSE 0 END), 0) as abnormalCount,
            COALESCE(COUNT(*), 0) as totalCount
        FROM
            asset_inventory_task_item
        WHERE
            inventory_task_id = #{taskId}
    </select>
 
</mapper>