SampleDistributionMapper.xml 5.5 KB
Newer Older
qinhu's avatar
1  
qinhu committed
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
<?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="cn.wise.sc.cement.business.mapper.SampleDistributionMapper">
    <sql id="where">
        <where>
            <if test="params.startDate != null and params.startDate != ''">
                and DATE(e.create_time) &gt;= #{params.startDate}
            </if>
            <if test="params.endDate != null and params.endDate != ''">
                and DATE(e.create_time) &lt;= #{params.endDate}
            </if>
            <if test="params.status != null">
                and t.status = #{params.status}
            </if>
            <if test="params.clientId != null">
                and e.client_id = #{params.clientId}
            </if>
            <if test="params.projectName != null and params.projectName != ''">
                and p.name like concat('%', #{params.projectName}, '%')
            </if>
            <if test="params.userId != null">
                and t.user_id = #{params.userId}
            </if>
        </where>
    </sql>
    <sql id="sampleDisWhere">
        <where>
            `status` > 5 AND d.distribution_id IS NOT NULL
            <if test="params.start_time != null and params.start_time != ''">
                and d.finish_time <![CDATA[>=]]> #{params.start_time}
            </if>
            <if test="params.end_time != null and params.end_time != ''">
                and d.finish_time  <![CDATA[<=]]> #{params.end_time}
            </if>
            <if test="params.user_id != null and params.user_id != ''">
                and d.user_id = #{params.user_id}
            </if>
        </where>

    </sql>
    <select id="getPage" resultType="cn.wise.sc.cement.business.model.vo.SampleDistributionVo">
        select t.*, p.id as projectId, p.name as projectName, p.code as projectCode,
        e.id as entrustId, e.entrust_date as entrustDate, e.sample_num sampleNum,
        su.name as userName
        from sample_distribution t
        left join sys_user su on su.id = t.user_id
        left join sample s on s.id = t.sample_id
        left join entrust e on e.id = s.entrust_id
        left join project p on p.id = e.project_id
        <include refid="where"/>
        order by t.create_time desc
    </select>

    <select id="getDistributionTeamList" resultType="cn.wise.sc.cement.business.model.vo.SampleDistributionTeamVo">
        select t.id as distributionId, su.id as userId, su.name as userName,
        t.team_group_id as teamGroupId, tg.name as teamGroupName, s.id as teamId, s.name as teamName,
        t.enclosure_url as enclosureUrl, t.alias as alias, t.ext_name as extName,
        t.status as status,
        (
        CASE t.status
        WHEN 0 THEN '未接受'
        WHEN 1 THEN '已接受'
        WHEN 2 THEN '已完成'
        ELSE ''
        END
        ) as statusValue
        from sample_distribution t
        left join sys_user su on su.id = t.user_id
        left join team s on s.id = t.team_id
        left join team_group tg on tg.id = t.team_group_id
        where t.sample_id = #{sampleId}
        <if test="userId != null">
            and t.user_id = #{userId}
        </if>
        order by t.id asc
    </select>

    <select id="getDistributionTeamGroupList" resultType="cn.wise.sc.cement.business.model.vo.SampleDistributionTeamVo">
        select su.id as userId,
        t.team_group_id as teamGroupId
        from sample_distribution t
        left join sys_user su on su.id = t.user_id
        left join team s on s.id = t.team_id
        left join team_group tg on tg.id = t.team_group_id
        where t.sample_id = #{sampleId}
        <if test="userId != null">
            and t.user_id = #{userId}
        </if>
        group by t.team_group_id
    </select>

    <select id="getSampleCheckGroupList" resultType="cn.wise.sc.cement.business.model.vo.SampleCheckGroupVo">
        select sd.team_group_id as teamGroupId, tg.name as teamGroupName,
				sd.user_id as userId, su.name as userName
        from sample_distribution sd
        left join team_group tg on tg.id = sd.team_group_id
		left join sys_user su on su.id = sd.user_id
        where tg.check_element is not null and sd.sample_id =  #{sampleId}
        group by sd.team_group_id,sd.user_id
        order by sd.team_group_id
    </select>

    <select id="getEntrustSample"
            resultType="cn.wise.sc.cement.business.entity.EntrustSample">
        SELECT e.project_name,e.entrust_code,g.distribution_id,g.entrust_id,g.`sample_name`,g.user_id,g.sample_id,e.`status` FROM entrust e
        RIGHT JOIN
            (SELECT s.`name` as sample_name,d.distribution_id,s.entrust_id,d.user_id,s.id as sample_id FROM sample s
        RIGHT JOIN
            (SELECT user_id, id as distribution_id,sample_id  FROM sample_distribution ) d on s.id = d.sample_id ) g
        ON g.entrust_id = e.id
        WHERE	e.status > 5
    </select>
    <select id="getSampleDistribution" resultType="cn.wise.sc.cement.business.entity.EntrustSample">

        SELECT
        project_name,entrust_code,id,d.distribution_id,s.sample_name,d.user_id,s.sample_id,d.team_group_id,d.finish_time,`status`
        FROM entrust e
        LEFT JOIN
        (SELECT `name` as sample_name,entrust_id,id as sample_id FROM sample) as s
        ON e.id = s.entrust_id
        LEFT JOIN
        (SELECT user_id, id as distribution_id,sample_id as dis_sample_id,team_group_id,finish_time FROM
        sample_distribution) as d
        ON s.sample_id = d.dis_sample_id
        <include refid="sampleDisWhere"/>
    </select>

</mapper>