EntrustMapper.xml 11.1 KB
<?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.EntrustMapper">

    <sql id="where">
        <where>
            and e.is_delete = 1
            <if test="params.startDate != null and params.startDate != ''">
                and DATE(e.entrust_date) &gt;= #{params.startDate}
            </if>
            <if test="params.endDate != null and params.endDate != ''">
                and DATE(e.entrust_date) &lt;= #{params.endDate}
            </if>
            <if test="params.status != null">
                and e.status = #{params.status}
            </if>
            <if test="params.reportStatus != null">
                and e.status  <![CDATA[>=]]>  #{params.reportStatus}
            </if>
            <if test="params.clientName != null and params.clientName != ''">
                and c.name like concat('%', #{params.clientName}, '%')
            </if>
            <if test="params.projectName != null and params.projectName != ''">
                and p.name like concat('%', #{params.projectName}, '%')
            </if>
            <if test="params.projectCode != null and params.projectCode != ''">
                and p.code like concat('%', #{params.projectCode}, '%')
            </if>
            <if test="params.userId != null">
                and e.user_id = #{params.userId}
            </if>
            <if test="params.projectType != null and params.projectType != ''">
                and e.project_type = #{params.projectType}
            </if>
            <if test="params.isUrgent != null">
                and e.is_urgent = #{params.isUrgent}
            </if>
        </where>
    </sql>

    <select id="getPage" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
        select e.*, c.name as clientName, su.name as userName,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as statusValue
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        <include refid="where"/>
        order by e.is_urgent desc, e.update_time desc
    </select>


    <select id="exportList" resultType="java.util.HashMap">
        SELECT
        (@i:=@i+1) as 序号,
        e.id as entrustId,
        IF(ISNULL(e.entrust_code),'',e.entrust_code) as 委托编号,
        (
        CASE e.is_urgent
        WHEN 0 THEN '不加急'
        WHEN 1 THEN '加急'
        ELSE NULL
        END
        ) as 是否加急,
        IF(ISNULL(e.project_name),'',e.project_name) as 项目名称,
        IF(ISNULL(e.project_code),'',e.project_code)  as 项目编号,
        IF(ISNULL(su.name),'',su.name) su.name as 委托人,
        IF(ISNULL(c.name),'',c.name) c.name as 委托单位,
        IF(ISNULL(e.entrust_date),'',e.entrust_date)   as 委托日期,
        IF(ISNULL(e.sample_num),'',e.sample_num)  as 样品数量,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as 状态
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        ,(select @i:=0)aa
        <include refid="where"/>
        order by 序号,e.is_urgent desc, e.update_time desc
    </select>


    <select id="getDetail" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
        select e.*,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as statusValue,
        p.name as projectName, c.name as clientName, su.name as userName,
        su.phone as userPhone, su.fax as userFax
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        where e.id = #{id}
    </select>


    <select id="getSampleHandlePage" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
        select e.id as id, e.entrust_code as entrustCode, e.sample_num as sampleNum,e.entrust_date as entrustDate,
        e.status,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as statusValue,
        p.id as projectId, p.name as projectName, p.code as projectCode,
        su.name as userName
        from sample_handle 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
        where 1=1
        <if test="params.userId != null">
            and t.user_id = #{params.userId}
        </if>
        <if test="params.projectCode != null and params.projectCode != ''">
            and p.code like concat('%', #{params.projectCode}, '%')
        </if>
        group by e.id
        order by e.update_time desc
    </select>


    <select id="getSampleDistributionPage" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
        select e.id as id, e.entrust_code as entrustCode, e.sample_num as sampleNum,e.entrust_date as entrustDate,
        e.status,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as statusValue,
        p.id as projectId, p.name as projectName, p.code as projectCode,
        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
        where 1=1
        <if test="params.userId != null">
            and t.user_id = #{params.userId}
        </if>
        <if test="params.projectCode != null and params.projectCode != ''">
            and p.code like concat('%', #{params.projectCode}, '%')
        </if>
        <if test="params.projectName != null and params.projectName != ''">
            and p.name like concat('%', #{params.projectName}, '%')
        </if>
        GROUP BY e.id
        order by e.update_time desc
    </select>

    <!--数据校核分页列表-->
    <select id="getCheckPage" resultType="cn.wise.sc.cement.business.model.vo.EntrustVo">
        select e.*, p.name as projectName, c.name as clientName, su.name as userName,
        (
        CASE e.status
        WHEN 0 THEN '未评审'
        WHEN 1 THEN '已通过'
        WHEN 2 THEN '未通过'
        WHEN 3 THEN '样品处理中'
        WHEN 4 THEN '样品处理完成'
        WHEN 5 THEN '样品检测中'
        WHEN 6 THEN '样品检测完成'
        WHEN 7 THEN '校核中'
        WHEN 8 THEN '校核完成'
        ELSE ''
        END
        ) as statusValue
        from entrust e
        left join project p on p.id = e.project_id
        left join client c on c.id = e.client_id
        left join sys_user su on su.id = e.user_id
        <include refid="checkWhere"/>
        order by e.update_time desc
    </select>

    <select id="getReportDetail" resultType="cn.wise.sc.cement.business.entity.EntrustReport">
        SELECT e.id,e.project_name,e.send_name,e.client_id,e.entrust_code,e.project_type,sscct.* FROM entrust e
        RIGHT JOIN
        (SELECT id,entrust_id,team_ids,method_numbers,name,scct.check_id,
        scct.equipment_name,scct.user_id,create_time as send_time,scct.equipment_id FROM sample s
        RIGHT JOIN
        (SELECT check_id,equipment_name,sample_id,user_id,equipment_id FROM sample_check_team sct
        RIGHT JOIN
        (SELECT entrust_id,id FROM sample_check WHERE entrust_id = #{entrustId}) sc
        ON sct.check_id = sc.id ) scct
        ON s.id = scct.sample_id) sscct
        ON sscct.entrust_id = e.id
        WHERE e.id IS NOT NULL
    </select>

    <select id="getQualityDetail" resultType="cn.wise.sc.cement.business.entity.QualityDetail">
        SELECT s.sample_name,s.cement_code,s.sample_form,s.sample_code,esscct.* FROM (SELECT
        sscct.*,client_id,entrust_code,project_name,sample_num,send_name,send_phone,create_time FROM entrust e
        RIGHT JOIN
        (SELECT count_result as input_result,sample_id,entrust_id,team_group_name,team_group_id,user_id FROM
        sample_check sc
        RIGHT JOIN
        (SELECT * FROM sample_check_team) sct
        ON sct.check_id = sc.id WHERE sc.entrust_id = #{entrustId}) sscct
        ON e.id = sscct.entrust_id) esscct
        LEFT JOIN
        (SELECT name as sample_name,id,cement_code,sample_form,sample_code FROM sample) s
        ON esscct.sample_id = s.id
    </select>

    <sql id="checkWhere">
        <where>
            and e.is_delete = 1 and e.status >= 6
            <if test="params.startDate != null and params.startDate != ''">
                and DATE(e.entrust_date) &gt;= #{params.startDate}
            </if>
            <if test="params.endDate != null and params.endDate != ''">
                and DATE(e.entrust_date) &lt;= #{params.endDate}
            </if>
            <if test="params.status != null">
                and e.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.projectCode != null and params.projectCode != ''">
                and p.code like concat('%', #{params.projectCode}, '%')
            </if>
            <if test="params.userId != null">
                and e.user_id = #{params.userId}
            </if>
        </where>
    </sql>

</mapper>