XiaoRuby
2023-09-07 c28d3bb363dde2afb44c168b93379b2bf6b1f67f
inspect-server/src/main/resources/mapper/InspectUnacceptedMapper.xml
@@ -1,48 +1,9 @@
<?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.yuanchu.mom.mapper.InspectUnacceptedMapper">
    <!--根据原材料检验单id删除原材料不合格品-->
    <update id="updaRawIns">
        update mom_ocean.inspect_unaccepted
        set state=0
        where raw_inspect_id = #{id}
          and type = 0
    </update>
    <!--根据原材料检验单id批量删除原材料不合格品-->
    <update id="delAllRawIns">
        update mom_ocean.inspect_unaccepted
        set state=0
        where raw_inspect_id in (${ids})
          and type = 0
    </update>
    <select id="selectUnRawInspectsList" resultType="java.util.Map">
        select ru.id,
        DATE_FORMAT(form_time, '%Y-%m-%d') '来料日期',
        reason,
        code,
        name,
        specifications,
        unit,
        number,
        DATE_FORMAT(ri.create_time, '%Y-%m-%d') '报检日期',
        user_name,
        DATE_FORMAT(ins_time, '%Y-%m-%d') '检验日期',
        deal_state,
        deal_reasult,
        DATE_FORMAT(deal_time, '%Y-%m-%d') '处理日期'
        from mom_ocean.raw_inspect ri inner join mom_ocean.inspect_unaccepted ru on ri.id = ru.raw_inspect_id
        <where>
            <if test="dealState!=null and dealState!=''">
                and deal_state=#{dealState}
            </if>
            <if test="formTime!=null and formTime!=''">
                and form_time=#{formTime}
            </if>
            and ru.state=1
        </where>
        order by ru.id desc
    </select>
    <!--不合格管理-->
    <select id="selectInsList" resultType="java.util.Map">
        SELECT ru.id,
        DATE_FORMAT(fi.create_time, '%Y-%m-%d') dateArrival,
@@ -57,7 +18,7 @@
        u.name,
        deal_state,
        deal_reasult,
        DATE_FORMAT(deal_time, '%Y-%m-%d') processingDate
        DATE_FORMAT(fi.update_time, '%Y-%m-%d') processingDate
        FROM (inspect_unaccepted ru,
        `user` u)
        LEFT JOIN finished_inspect fi ON fi.`id` = ru.`raw_inspect_id`
@@ -65,8 +26,8 @@
        AND ru.type = 1
        AND ru.state=1
        AND fi.`user_id` = u.`id`
        <if test="dealState!=null and dealState!=''">
            and deal_state=#{dealState}
        <if test="dealState!=null">
            and deal_state = #{dealState}
        </if>
        <if test="formTime!=null and formTime!=''">
            and fi.create_time=#{formTime}
@@ -74,9 +35,10 @@
        order by ru.id desc
    </select>
    <!--原材料不合格-->
    <select id="selectUnqualifiedRawMaterials" resultType="map">
        SELECT i.id,
               DATE_FORMAT(r.create_time, '%Y-%m-%d') dateArrival,
               DATE_FORMAT(r.form_time, '%Y-%m-%d') dateArrival,
               i.`reason`,
               r.`code`,
               r.`name`,
@@ -94,7 +56,7 @@
        WHERE i.`state` = 1
          AND i.`type` = 0
        <if test="formTime != null and formTime != ''">
            AND r.create_time = #{formTime}
            AND r.form_time = #{formTime}
        </if>
        <if test="productName != null and productName != ''">
            AND r.name LIKE CONCAT('%', #{productName}, '%')
@@ -107,4 +69,57 @@
        </if>
        ORDER BY i.`id` DESC
    </select>
    <!--不合格处置-->
    <select id="selectDisposal" resultType="map">
        SELECT i.`id`, s.`type`, s.name productName, s.`specifications`, s.number, i.`tell` description,
        o.`tell` opinions, s.user_name, DATE_FORMAT(i.`create_time`, '%Y-%m-%d') `date`, i.`deal_state`
        FROM inspect_unaccepted i
        LEFT JOIN
        (
            -- 原材料
            SELECT 0 AS `type`, r.`name`, r.`specifications`, r.`number`, r.`id`, r.`user_name`
            FROM raw_inspect r
            WHERE r.state = 1
            <if test="specificationModel != null and specificationModel != ''">AND r.`specifications` LIKE CONCAT('%',
                #{specificationModel}, '%')
            </if>
            <if test="
            productName != null and productName != ''">AND r.`name` LIKE CONCAT('%', #{productName}, '%')
            </if>
            UNION ALL
            -- 成品
            SELECT 1 AS `type`, f.`project_name` `name`, f.`specifications_model` specifications, f.`quantity` `number`, f.`id`, u.name user_name
            FROM finished_inspect f, `user` u
            WHERE f.`state` = 1
              AND u.id = f.user_id
            <if test="specificationModel != null and specificationModel != ''">
                AND f.`specifications_model` LIKE CONCAT('%', #{specificationModel}, '%')
            </if>
            <if test="productName != null and productName != ''">
                AND f.`project_name` LIKE CONCAT('%', #{productName}, '%')
            </if>
            UNION ALL
            -- 半成品
            SELECT 2 AS `type`, p.`material` `name`, p.`specifications_model` specifications, p.`quantity` `number`, p.`id`, u.name user_name
            FROM process_inspect p, `user` u
            WHERE p.state = 1
                AND u.id = p.user_id
            <if test="specificationModel != null and specificationModel != ''">
                AND p.`specifications_model` LIKE CONCAT('%', #{specificationModel}, '%')
            </if>
            <if test="productName != null and productName != ''">
                AND p.`material` LIKE CONCAT('%', #{productName}, '%')
            </if>
         )AS s ON s.`id` = i.`raw_inspect_id` AND s.`type` = i.type
        LEFT JOIN opinion o ON i.`id` = o.`raw_unaccepted_id`
        WHERE i.`state` = 1
        <if test="state != null">
            AND i.`deal_state` = #{state}
        </if>
        <if test="productCategories != null">
            AND s.`type` = #{productCategories}
        </if>
        ORDER BY i.id DESC
    </select>
</mapper>