ganzi-api/inventory-dao/src/main/resources/mapper/EntPostListMapper.xml

91 lines
4.2 KiB
XML
Raw Normal View History

<?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.rzyc.mapper.EntPostListMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.rzyc.model.EntPostList">
<id column="post_list_id" property="postListId" />
<result column="post_id" property="postId" />
<result column="ent_user_id" property="entUserId" />
<result column="enterprise_id" property="enterpriseId" />
<result column="ent_list_id" property="entListId" />
<result column="list_id" property="listId" />
<result column="item_title" property="itemTitle" />
<result column="item_content" property="itemContent" />
<result column="sort_id" property="sortId" />
<result column="year_num" property="yearNum" />
<result column="standard" property="standard" />
<result column="frequency" property="frequency" />
<result column="finish_state" property="finishState" />
<result column="red_alert" property="redAlert" />
<result column="yellow_alert" property="yellowAlert" />
<result column="del_state" property="delState" />
<result column="create_time" property="createTime" />
<result column="create_by" property="createBy" />
<result column="modify_time" property="modifyTime" />
<result column="modify_by" property="modifyBy" />
<result column="finishCount" property="finishCount"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
post_list_id, post_id, ent_user_id, enterprise_id, ent_list_id, list_id, item_title, item_content, sort_id, year_num, standard, frequency, finish_state, red_alert, yellow_alert, del_state, create_time, create_by, modify_time, modify_by
</sql>
<select id="selectEntPostList" resultMap="BaseResultMap">
select epl.*,sum(case when task_state = 2 then 1 else 0 end)as finishCount from ent_post_list epl left join ent_post_task ept on epl.post_list_id = ept.post_list_id
where epl.enterprise_id = #{enterpriseId} and epl.ent_user_id = #{entUserId}
<if test="null != finishedState and '' != finishedState">
and epl.finish_state = #{finishedState}
</if>
<if test="null !=postId and '' != postId">
and epl.post_id = #{postId}
</if>
group by epl.post_list_id
</select>
<select id="selectEntPostListCount" resultType="java.lang.Integer">
select count(post_list_id) from ent_post_list where enterprise_id = #{enterpriseId}
<if test="null != listId and '' != listId">
and list_id = #{listId}
</if>
<if test="null != year">
and `year_num` = #{year}
</if>
</select>
<select id="selectEntPostListFinishedCount" resultType="java.lang.Integer">
select count(post_list_id) from ent_post_list where enterprise_id = #{enterpriseId}
<if test="null != listId and '' != listId">
and list_id = #{listId}
</if>
<if test="null != state and '' != state">
and finish_state = #{state}
</if>
<if test="null != year">
and `year_num` = #{year}
</if>
</select>
<resultMap id="EntListGroupMap" type="com.rzyc.model.EntPostList">
<result column="list_id" property="listId" />
<result column="item_title" property="itemTitle" />
<result column="totalTaskNumber" property="totalTaskNumber"/>
<result column="haveInHand" property="haveInHand"/>
</resultMap>
<select id="selectEntListGroupByListId" resultMap="EntListGroupMap">
select epl.list_id,epl.item_title,count(ept.task_id)as totalTaskNumber,sum(case when task_state = 1 then 1 else 0 end)as haveInHand
from ent_post_list epl
left join ent_post_task ept on epl.post_list_id = ept.ent_list_id
where epl.enterprise_id = #{enterpriseId} and epl.ent_user_id = #{userId}
<if test="null != listId and '' != listId">
and epl.list_id = #{listId}
</if>
group by epl.list_id,epl.item_title
</select>
</mapper>