廖井涛
2024-03-15 5a5e59f8aaa2a030511ef245886bf6d1db9bf774
north-glass-erp/target/classes/mapper/pp/ReportingWork.xml
@@ -9,18 +9,34 @@
        <result property="previousProcess" column="previous_process"/>
        <result property="nextProcess" column="next_process"/>
        <result property="thisProcess" column="this_process"/>
        <result property="reviewedState" column="reviewed_state"/>
        <result property="previousProcessQuantity" column="previous_process_quantity"/>
        <result property="reportingWorkTime" column="reporting_work_time"/>
        <result property="thisCompletedQuantity" column="this_completed_quantity"/>
        <result property="thisWornQuantity" column="this_worn_quantity"/>
        <result property="deviceName" column="device_name"/>
        <result property="teamsGroupsName" column="teams_groups_name"/>
        <result property="reviewedState" column="reviewed_state"/>
        <result property="reportingWorkId" column="reporting_work_id"/>
        <result property="processId" column="process_id"/>
        <result property="completedArea" column="completedArea"/>
        <result property="wornArea" column="wornArea"/>
        <association property="order" javaType="com.example.erp.entity.sd.Order">
            <result property="customerId" column="customer_id"/>
            <result property="customerName" column="customer_name"/>
            <result property="project" column="project"/>
            <result property="batch" column="batch"/>
        </association>
        <association property="flowCard" javaType="com.example.erp.entity.pp.FlowCard">
            <result property="orderId" column="order_id"/>
            <result property="productionId" column="production_id"/>
            <result property="quantity" column="quantity"/>
        </association>
        <association property="reportingWorkDetail" javaType="com.example.erp.entity.pp.ReportingWorkDetail">
            <result property="completedQuantity" column="completed_quantity"/>
        </association>
        <association property="orderGlassDetail" javaType="com.example.erp.entity.sd.OrderGlassDetail">
            <result property="area" column="area"/>
        </association>
    </resultMap>
@@ -31,14 +47,20 @@
               o.customer_id,
               o.customer_name,
               o.project,
               SUM(fc.quantity)   as quantity,
               SUM(fc.quantity)   as previous_process_quantity,
               #{previousProcess} as previous_process,
               #{nextProcess}     as next_process,
               #{process} as  this_process
               #{process} as  this_process,
               ifnull((rw.reviewed_state),1) as reviewed_state  -- 下工序审核状态
        from sd.order as o
                 left join flow_card as fc on fc.order_id = o.order_id
        left join flow_card as fc on fc.order_id = o.order_id
        left join (select if(count(reviewed_state)>0 and process_id=null,1,0) as reviewed_state ,
                          process_id
                   from reporting_work
                   where this_process=#{previousProcess} and reviewed_state=0 and process_id=#{processIdStr}) as rw
        on rw.process_id = fc.process_id
        where fc.process_id = #{processIdStr}
          and position(fc.technology_number in #{technologyStr})
          and fc.technology_number = #{technologyStr}
        GROUP BY fc.process_id
    </select>
@@ -80,59 +102,458 @@
            ogd.child_width,
            ogd.child_height,
            od.shape,
            fc.quantity - IFNULL(fc.number_patches,0)-IFNULL(rwd.completed_quantity,0)-IFNULL(rwd.breakage_quantity,0)-IFNULL((rwd.wait_rework_quantity),0)
                        as quantity
            fc.quantity -odpd.reporting_work_num -odpd.broken_num + ifnull(c.patchNumSum,0) as quantity,
            fc.quantity -odpd.reporting_work_num -odpd.broken_num + ifnull(c.patchNumSum,0) as completedQuantity,
            odpd.reporting_work_num as completed,
            odpd.broken_num as onceBroken,
            if(fc.quantity -odpd.reporting_work_num = 0 ,true,false) as saveFlag -- 判断是否已经完成,已经完成不序号和同序号数量相同才能提交
        FROM
            sd.order_detail AS od
                LEFT JOIN sd.order_glass_detail AS ogd ON od.order_id = ogd.order_id
                AND od.order_number = ogd.order_number
                LEFT JOIN flow_card AS fc ON fc.order_id = ogd.order_id and fc.production_id=ogd.production_id
                AND fc.order_number = ogd.order_number
                AND fc.technology_number = ogd.technology_number
                left join reporting_work as rw on rw.order_id=fc.order_id and rw.production_id=fc.production_id and rw.process_id=fc.process_id
                left join reporting_work_detail as rwd on rwd.reporting_work_id=rw.reporting_work_id and rwd.order_number=fc.order_number and rwd.technology_number=fc.technology_number
        LEFT JOIN sd.order_glass_detail AS ogd
            ON od.order_id = ogd.order_id
            AND od.order_number = ogd.order_number
        LEFT JOIN flow_card AS fc
            ON fc.order_id = ogd.order_id
            and fc.production_id=ogd.production_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
        left join sd.order_process_detail as odpd
            ON  odpd.order_id = fc.order_id
            AND odpd.order_number = fc.order_number
            AND odpd.technology_number = fc.technology_number
            and  odpd.process_id = fc.process_id
        left join
                (select sum(patch_num) as patchNumSum,order_sort,technology_number,process_id
                   from patch_log
                   group by reporting_work_id,order_sort,technology_number) as c
            on c.process_id = fc.process_id
            and c.order_sort = fc.order_number
            and c.technology_number = fc.technology_number
        WHERE
            fc.process_id = #{processIdStr}
          AND position(
                fc.technology_number IN #{technologyStr})
          AND fc.technology_number = #{technologyStr}
          AND odpd.process = #{process}
        order by fc.order_number
    </select>
<!--    非第一道工序报工明细查询-->
    <select id="SelectReworlDetailMp">
        SELECT fc.order_number,
               ogd.glass_child,
               ogd.technology_number,
               ogd.glass_address,
               fc.quantity as quantity_card,
               ogd.child_width,
               ogd.child_height,
               od.shape,
               reportingwork_num -IFNULL(rwd.completed_quantity,0)-IFNULL(rwd.breakage_quantity,0)-IFNULL((rwd.wait_rework_quantity),0) as quantity
        FROM sd.order_detail as od
                 left join sd.order_glass_detail as ogd
                           on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                 left join sd.order_process_detail as opd
                           on opd.order_id = ogd.order_id and opd.order_number = ogd.order_number and
                              opd.technology_number = ogd.technology_number
        SELECT
            fc.order_number,
            ogd.glass_child,
            ogd.technology_number,
            ogd.glass_address,
            fc.quantity AS quantity_card,
            ogd.child_width,
            ogd.child_height,
            od.shape,
            odpds.reporting_work_num -odpd.reporting_work_num -odpd.broken_num + ifnull(c.patchNumSum,0) as quantity,
            odpds.reporting_work_num -odpd.reporting_work_num -odpd.broken_num + ifnull(c.patchNumSum,0) as completedQuantity,
            odpd.reporting_work_num as completed,
            odpd.broken_num as onceBroken,
            ogd.`group`,
            if(fc.quantity -odpd.reporting_work_num = 0 ,true,false) as saveFlag -- 判断是否已经完成,已经完成不序号和同序号数量相同才能提交
                 left join flow_card as fc on opd.order_id = fc.order_id and opd.order_number = fc.order_number and
                                              opd.technology_number = fc.technology_number
                 left join reporting_work as rw on rw.order_id=fc.order_id and
                                                   rw.production_id=fc.production_id and rw.process_id=fc.process_id and rw.this_process = #{previousProcess}
                 left join reporting_work_detail as rwd on rwd.reporting_work_id=rw.reporting_work_id and
                                                           rwd.order_number=fc.order_number and rwd.technology_number=fc.technology_number
        where fc.process_id = #{processIdStr}
          and opd.process = #{previousProcess}
          and position(ogd.technology_number in #{technologyStr})
        FROM
            sd.order_detail AS od
        LEFT JOIN sd.order_glass_detail AS ogd
                ON od.order_id = ogd.order_id
                AND od.order_number = ogd.order_number
        <if test="process == '夹胶'">
            AND ogd.`group` = (select `group`
                               from sd.order_glass_detail
                               where order_id = ogd.order_id
                               and order_number = ogd.order_number
                               and technology_number =#{technologyStr}
                               limit 1)
        </if>
        LEFT JOIN flow_card AS fc
                ON fc.order_id = ogd.order_id
                and fc.production_id=ogd.production_id
                AND fc.order_number = ogd.order_number
                AND fc.technology_number = ogd.technology_number
        left join sd.order_process_detail as odpd
                ON  odpd.order_id = fc.order_id
                AND odpd.order_number = fc.order_number
                AND odpd.technology_number = fc.technology_number
                and odpd.process_id = fc.process_id
        left join sd.order_process_detail as odpds
                ON  odpds.id = odpd.id-1
        left join
            (select sum(patch_num) as patchNumSum,order_sort,technology_number,process_id
             from patch_log
             group by reporting_work_id,order_sort,technology_number) as c
            on c.process_id = fc.process_id
            and c.order_sort = fc.order_number
            and c.technology_number = fc.technology_number
        WHERE
            fc.process_id = #{processIdStr}
        <if test="process != '中空' and process != '夹胶' and process != '包装'">
           AND fc.technology_number = #{technologyStr}
        </if>
        AND odpd.process = #{process}
        order by fc.order_number
    </select>
    <select id="SelectProcessMp">
        select * from sd.basic_data where basic_type="product" and basic_category="process"
        select * from sd.basic_data where basic_type='product' and basic_category='process'
    </select>
    <select id="historyProcessMp">
        select ifnull(GROUP_CONCAT(distinct rw.this_process),'') from reporting_work as rw where rw.process_id=#{processIdStr}
    </select>
    <select id="historyDeviceMp">
        SELECT
            bdp.id,
            bdp.basic_type,
            bdp.basic_name,
            bd.basic_name AS basic_category
        FROM
            sd.basic_data AS bd
                LEFT JOIN `basic_data_produce` AS bdp ON bd.id = bdp.basic_category
        WHERE
            bd.basic_category = 'process'
          AND bdp.basic_type = 'device'
          AND POSITION(bd.basic_name in CONCAT(#{historyProcess},#{process}))
    </select>
    <select id="historyTeamsMp">
        SELECT
            bdp.id,
            bdp.basic_type,
            bdp.basic_name,
            bd.basic_name,bd.id AS basic_category,
            rw.process
        FROM
            sd.basic_data AS bd
        LEFT JOIN `basic_data_produce` AS bdp
            ON bd.id = bdp.basic_category
        right join (
                    select distinct process from
                        (   select distinct rw.this_process as  process
                            from reporting_work as rw where rw.process_id=#{processIdStr}
                            UNION
                            select #{process}
                        ) as t
                    ) as  rw
        on rw.process=bd.basic_name
        WHERE
           bdp.basic_type = 'teamsgroups'
    </select>
    <select id="SelectHistoryProcessMp">
        SELECT
            distinct
            bd.basic_name AS basic_category
        FROM
            sd.basic_data AS bd
                LEFT JOIN `basic_data_produce` AS bdp ON bd.id = bdp.basic_category
        WHERE
            bd.basic_category = 'process'
          AND bdp.basic_type = 'teamsgroups'
          AND POSITION(bd.basic_name in CONCAT(#{historyProcess},#{process}))
    </select>
    <select id="selectBasicNameByType">
        select * from `basic_data_produce` as a where a.basic_type  = #{type}
    </select>
    <select id="selectMaxReportingWorkId">
        select
            ifnull(SUBSTR(max(reporting_work_id) from 9),0)
        from
            reporting_work as a
        where
            date(a.create_time) = curdate()
        order by id desc,reporting_work_id   desc limit  1
    </select>
    <!--    查询流程卡工序报工可报数量-->
    <select id="selectReportingWorkNum">
    </select>
    <select id="selectGlassProcessNum" resultType="java.lang.Integer">
        select
              d.reporting_work_num-b.reporting_work_num-b.broken_num+ifnull(c.patchNumSum,0)
        from flow_card as a
        left join sd.order_process_detail as b
        on
            b.order_number = a.order_number
            and b.technology_number = a.technology_number
            and b.order_id = SUBSTR(#{processId} from 1 for 10)
            and b.process = #{thisProcess}
            and b.process_id = a.process_id
        left join sd.order_process_detail as d
            on d.id=b.id-1
        left join (select sum(patch_num) as patchNumSum,order_sort,technology_number,process_id
                   from patch_log
                   group by reporting_work_id,order_sort,technology_number) as c
        on
            c.process_id = a.process_id
            and c.order_sort = a.order_number
            and c.technology_number = a.technology_number
        where
            a.process_id=SUBSTR(#{processId} from 1 for 13)
            and a.order_number = #{orderNumber}
            and a.technology_number = #{technologyNumber}
    </select>
    <select id="selectFlowCardNum" resultType="java.lang.Integer">
        select
                    a.quantity-b.reporting_work_num-b.broken_num+ifnull(c.patchNumSum,0)
        from flow_card as a
                 left join sd.order_process_detail as b
                           on
                                       b.order_number = a.order_number
                                   and b.technology_number = a.technology_number
                                   and b.order_id = SUBSTR(#{processId} from 1 for 10)
                                   and b.process = #{thisProcess}
                                   and b.process_id = a.process_id
                 left join (select sum(patch_num) as patchNumSum,order_sort,technology_number,process_id
                            from patch_log
                            group by reporting_work_id,order_sort,technology_number) as c
                           on
                                       c.process_id = a.process_id
                                   and c.order_sort = a.order_number
                                   and c.technology_number = a.technology_number
        where
            a.process_id=SUBSTR(#{processId} from 1 for 13)
          and a.order_number = #{orderNumber}
          and a.technology_number = #{technologyNumber}
    </select>
<!--查询修改报工明细数据-->
    <select id="selectByReportingWorkId" >
        select
            a.reporting_work_id,
            d.order_number,
            d.glass_child,
            d.technology_number,
            d.glass_address,
            c.quantity as quantity_card,
            d.child_width,
            d.child_height,
            e.shape,
            a.completed_quantity+a.breakage_quantity as 'quantity', -- 可报工数
            a.completed_quantity as 'completedQuantity', -- 完工数
            a.breakage_quantity as 'breakageQuantity', -- 破损数
            f.completed_quantity as thisQuantitySum ,-- 本工序完工和
            if(c.quantity-f.completed_quantity = 0 ,true,false) as saveFlag,
            <if test="nextProcess != null and nextProcess != ''">  -- 非最后一道工序
                ifnull(g.completed_quantity,0) as nextQuantitySum,  -- 后工序已完成
                if((f.completed_quantity
                    -ifnull(g.completed_quantity,0))
                    &gt;=
                   a.completed_quantity,
                    0,
                   (a.completed_quantity-f.completed_quantity
                       +ifnull(g.completed_quantity,0))
                    )  as minQuantity -- 修改最小数
            </if>
            <if test="nextProcess == null or nextProcess == ''">  -- 最后一道工序
#               c.received_quantity, -- 已入库数量
#               c.inventory_quantity, --   库存数量
              if(ifnull(inventory_quantity,0)
                 -ifnull(c.received_quantity,0)
                 &gt;= a.completed_quantity,0,
                (a.completed_quantity-(ifnull(c.inventory_quantity,0)
                    -ifnull(c.received_quantity,0)))
                )
                as minQuantity -- 修改最小数
            </if>
            -- e.thisQuantitySum
        from
            reporting_work_detail as a
            left join reporting_work as b
                on  a.reporting_work_id = b.reporting_work_id
            left join  flow_card as c
                on c.process_id = b.process_id
                and c.technology_number = a.technology_number
            left join  sd.order_glass_detail as d
                on d.order_id = c.order_id
                and c.order_number = d.order_number
                and d.technology_number = c.technology_number
            left join sd.order_detail as e
                on e.order_id = d.order_id and e.order_number = d.order_number
            left join (select sum(completed_quantity) as completed_quantity ,
                              rw.process_id,
                              rwd.order_number,
                              rwd.technology_number,
                              rw.this_process
                       from reporting_work as rw
                       left join  reporting_work_detail  as rwd
                       on rw.reporting_work_id = rwd.reporting_work_id
                       group by rw.process_id,
                                rw.this_process,
                                rwd.order_number,
                                rwd.technology_number
                       ) as f
            on f.process_id = b.process_id
            and f.this_process = b.this_process
            and f.order_number = a.order_number
            and f.technology_number = a.technology_number
        <if test="nextProcess != null and nextProcess != ''">
            left join (select ifnull(sum(completed_quantity),0) as completed_quantity ,
                            rw.process_id,
                            rwd.order_number,
                            rwd.technology_number,
                            rw.this_process
                           from reporting_work as rw
                           left join  reporting_work_detail  as rwd
                           on rw.reporting_work_id = rwd.reporting_work_id
                           group by rw.process_id,
                                    rw.this_process,
                                    rwd.order_number,
                                    rwd.technology_number
                    ) as g
                  on g.process_id = b.process_id
                  and g.this_process = b.next_process
                  and g.order_number = a.order_number
                  and g.technology_number = a.technology_number
        </if>
        where a.reporting_work_id = #{reportingWorkId}
    </select>
<select id="selectReportingWorkMp" resultMap="reportingWorkMap">
        select rw.reporting_work_id,
               (rw.reporting_work_time) as reporting_work_time,
               o.order_id,
               rw.process_id,
               o.project,
               o.batch,
               rw.this_process,
               rw.this_completed_quantity,
               (ogd.area * rw.this_completed_quantity) as completedArea,
               rw.this_worn_quantity,
               (ogd.area * rw.this_worn_quantity)      as wornArea,
               rw.device_name,
               rw.teams_groups_name,
               rw.reviewed_state
        # (IF(rw.reviewed_state = 0, '未审核', IF(rw.reviewed_state = 1, '审核通过', '审核不通过'))) as reviewed_state
        from sd.order as o
                 left join sd.order_glass_detail as ogd on ogd.order_id = o.order_id
                 left join reporting_work as rw on rw.order_id = ogd.order_id and rw.production_id = ogd.production_id
                 left join reporting_work_detail as rwd
                           on rwd.reporting_work_id = rw.reporting_work_id and rwd.order_number = ogd.order_number and
                              rwd.technology_number = ogd.technology_number
        where rw.reviewed_state != 2
          and rw.reporting_work_time between #{selectTime1} and #{selectTime2} and position(#{orderId} in rw.order_id)
          and rw.reviewed_state!=-1
        <if test="reportingWork.reportingWorkId != null and reportingWork.reportingWorkId != ''">
            and rw.reporting_work_id regexp #{reportingWork.reportingWorkId}
        </if>
        <if test="reportingWork.orderId != null and reportingWork.orderId != ''">
            and o.order_id regexp #{reportingWork.orderId}
        </if>
        <if test="reportingWork.processId != null and reportingWork.processId != ''">
            and rw.process_id regexp #{reportingWork.processId}
        </if>
        <if test="reportingWork.order.project != null and reportingWork.order.project != ''">
            and o.project regexp #{reportingWork.order.project}
        </if>
        <if test="reportingWork.order.batch != null and reportingWork.order.batch != ''">
            and o.batch regexp #{reportingWork.order.batch}
        </if>
        <if test="reportingWork.thisProcess != null and reportingWork.thisProcess != ''">
            and rw.this_process regexp #{reportingWork.thisProcess}
        </if>
        GROUP BY rw.reporting_work_id
        ORDER BY rw.reporting_work_id desc
        limit #{offset},#{pageSize};
    </select>
    <select id="getPageTotal">
        select CEILING(count(rw.reporting_work_id)/#{pageSize}) as 'pageTotal',
               count(distinct rw.reporting_work_id) as 'total'
             from sd.order as o
                 left join sd.order_glass_detail as ogd on ogd.order_id = o.order_id
                 left join reporting_work as rw on rw.order_id = ogd.order_id and rw.production_id = ogd.production_id
                 left join reporting_work_detail as rwd
                           on rwd.reporting_work_id = rw.reporting_work_id and rwd.order_number = ogd.order_number and
                              rwd.technology_number = ogd.technology_number
        where rw.reviewed_state != 2
          and rw.reporting_work_time between #{selectTime1} and #{selectTime2} and position(#{orderId} in rw.order_id)
          and rw.reviewed_state!=-1
        ORDER BY rw.reporting_work_id desc
        limit #{offset},#{pageSize};
    </select>
<!--    根据报工编号查询下工序-->
    <select id="selectNextProcess">
        select next_process from reporting_work where reporting_work_id=#{reportingWorkId}
    </select>
<!--    查询下工序是否报工-->
    <select id="selectCountByProcessId">
        select count(reporting_work_id) from reporting_work where this_process=#{nextProcess} and process_id=#{processId}
    </select>
<!--    查询完工次破数量-->
    <select id="reportingWorkDate">
        select rw.process_id,
               rwd.order_number,
               rwd.technology_number,
               rwd.completed_quantity,
               IFNULL(SUM(dd.breakage_quantity), 0) as breakage_quantity
        from reporting_work as rw
                 left join reporting_work_detail as rwd on rw.reporting_work_id = rwd.reporting_work_id
                 left join damage_details as dd
                           on dd.reporting_work_id = rwd.reporting_work_id and dd.order_number = rwd.order_number and
                              dd.technology_number = rwd.technology_number
        where rw.reporting_work_id = #{reportingWorkId}
        GROUP BY rwd.order_number, rwd.technology_number
    </select>
<!--    修改报工流程卡表数据-->
    <update id="updateWorkProcess">
        update sd.order_process_detail
        set reporting_work_num_count=reporting_work_num_count - #{completedQuantity},
            reporting_work_num=reporting_work_num - #{completedQuantity},
            broken_num=broken_num - #{breakageQuantity}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
          and process = #{thisProcess}
    </update>
<!--    删除报工-->
    <update id="deleteWork">
        update reporting_work set reviewed_state=-1
        where reporting_work_id = #{reportingWorkId}
    </update>
<!--    获取最后一道工序-->
    <select id="selectLastProcess">
        select process
        from sd.order_process_detail
        where process_id = #{processId}
          and order_number = 1
          and technology_number = 1
        order by id desc
        LIMIT 1
    </select>
<!--    查询可入库、已入库数量-->
    <select id="selectReceiptQuantity">
        select ifnull(SUM(quantity),0)                     as quantity,
               ifnull(SUM(inventory_quantity), 0) as inventoryQuantity,
               ifnull(SUM(received_quantity), 0) as receivedQuantity
        from flow_card
        where process_id = #{processId}
          and technology_number = 1
        GROUP BY process_id
    </select>
<!--    查询报工编号完工数量-->
    <select id="selectCompletedQuantity">
        select ifnull(this_completed_quantity,0) from reporting_work where reporting_work_id=#{reportingWorkId}
    </select>
<!--    更新流程卡可入库数量-->
    <update id="updateInventoryQuantity">
        update flow_card
        set inventory_quantity = inventory_quantity - #{completedQuantity}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
    </update>
</mapper>