chenlu
2024-10-11 82a5de6d2ec80b45660149c84be28734032562f6
north-glass-erp/src/main/resources/mapper/sd/CustomerMapper.xml
New file
@@ -0,0 +1,333 @@
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.erp.mapper.sd.CustomerMapper">
    <resultMap id="selectCustomerOrderDetail" type="com.example.erp.entity.sd.OrderDetail">
        <result column="order_id" property="orderId"/>
        <result column="order_number" property="orderNumber"/>
        <result column="quantity" property="quantity"/>
        <result column="building_number" property="buildingNumber"/>
        <result column="product_name" property="productName"/>
        <result column="product_id" property="productId"/>
        <result column="price" property="price"/>
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="area" property="area"/>
        <result column="shape" property="shape"/>
        <result column="gross_area" property="grossArea"/>
        <result column="compute_area" property="computeArea"/>
        <result column="compute_gross_area" property="computeGrossArea"/>
        <result column="processing_note" property="processingNote"/>
        <result column="edging_type" property="edgingType"/>
        <result column="perimeter" property="perimeter"/>
        <result column="batch" property="order.batch"/>
        <result column="project" property="order.project"/>
        <result column="customer_id" property="order.customerId"/>
        <result column="customer_name" property="order.customerName"/>
        <result column="money" property="order.money"/>
        <result column="order_type" property="order.orderType"/>
        <result column="salesman" property="order.salesman"/>
        <result column="create_time" property="order.createTime"/>
    </resultMap>
    <select id="getSelectCustomerDeliveryDate" >
        select d.delivery_id,dd.order_id,d.customer_id,d.customer_name,
               d.project,od.product_name,sum(dd.quantity) as quantity,sum(dd.area) as area,dd.price,sum(dd.money) as money,
                date(d.create_time) as create_time
        from sd.delivery_detail dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.order_detail od on od.order_id=dd.order_id and od.order_number=dd.order_number
                where date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
                and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectCustomerDeliveryDatePageTotal" >
        select
        CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
        count(zu.id) as 'total' from (select od.product_id,od.id
        from sd.delivery_detail dd
        left join sd.delivery d on d.delivery_id = dd.delivery_id
        left join sd.order_detail od on od.order_id=dd.order_id and od.order_number=dd.order_number
        where
             date(d.create_time)>=#{startDate} and date(d.create_time) &lt;= #{endDate}
            and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id) as zu
    </select>
    <select id="getSelectCustomerOderDate" >
        select od.order_id,
        od.order_number,
        o.project,
        od.product_id,
        od.product_name,
        o.customer_id,
        o.customer_name,
        sum(od.quantity) as quantity,
        sum(od.compute_gross_area) as area,
        od.shape,
        od.width,
        od.height,
        o.batch,
        od.price,
        sum(od.gross_amount) as money,
        o.order_type,
        o.salesman,
        date(o.create_time) as create_time
        from order_detail od
        left join `order` o on o.order_id = od.order_id
        <where>
            and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
                                   and o.customer_id = #{orderDetail.order.customerId} and o.create_order>0
        </where>
        group by od.order_id,od.product_id
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectCustomerOderDatePageTotal" >
        select
        CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
        count(zu.id) as 'total' from (select od.product_id,od.id
        from order_detail od
        left join `order` o on o.order_id = od.order_id
        <where>
            and date(o.create_time)>=#{startDate} and date(o.create_time) &lt;= #{endDate}
                and o.customer_id = #{orderDetail.order.customerId} and o.create_order>0
        </where>
        group by od.order_id,od.product_id) as zu
    </select>
    <select id="getCustomerList">
        select
            a.*,
            b.project,
            b.salesman_id,
            b.salesman
        from
            sd.customer as a
        left join (SELECT
                       t.*
                   FROM
                       (
                           SELECT
                               ROW_NUMBER() over ( PARTITION BY o.customer_id ORDER BY o.id DESC ) AS rn,
                               o.id,
                               o.project,
                               o.salesman_id,
                               o.salesman,
                               o.customer_id
                           FROM
                               sd.ORDER AS o
                       ) t
                   WHERE
                       rn = 1) as b
        on a.id = b.customer_id
    </select>
    <select id="getSelectCustomer">
        select
            *
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.customerAbbreviation != null and customer.customerAbbreviation != ''">
                and c.customer_abbreviation regexp #{customer.customerAbbreviation}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
        </where>
        limit #{offset},#{pageSize};
    </select>
    <select id="getSelectCustomerPageTotal">
        select
            CEILING(count(id)/#{pageSize}) as 'pageTotal',
            count(id) as 'total'
        from
            sd.customer c
        <where>
            <if test="customer.id != null and customer.id != ''">
                and c.id regexp #{customer.id}
            </if>
            <if test="customer.customerName != null and customer.customerName != ''">
                and c.customer_name regexp #{customer.customerName}
            </if>
            <if test="customer.grade != null and customer.grade != ''">
                and c.grade regexp #{customer.grade}
            </if>
            <if test="customer.moneyLimit != null and customer.moneyLimit != ''">
                and c.money_limit regexp REGEXP_REPLACE(#{customer.moneyLimit},'\\.0+$','')
            </if>
            <if test="customer.address != null and customer.address != ''">
                and c.address regexp #{customer.address}
            </if>
            <if test="customer.contact != null and customer.contact != ''">
                and c.contact regexp #{customer.contact}
            </if>
            <if test="customer.phone != null and customer.phone != ''">
                and c.phone regexp #{customer.phone}
            </if>
        </where>
        limit #{offset},#{pageSize};
    </select>
    <insert id="insertCustomer"  useGeneratedKeys="true" >
        insert into sd.customer(customer_name,customer_abbreviation,grade,money_limit,address,contact,phone)
        values (
                   #{customer.customerName},#{customer.customerAbbreviation},#{customer.grade},#{customer.moneyLimit},
                #{customer.address},#{customer.contact},#{customer.phone}
               )
    </insert>
    <update id="updateCustomer"  useGeneratedKeys="true" >
        update sd.customer set customer_name=#{customer.customerName},customer_abbreviation=#{customer.customerAbbreviation},grade=#{customer.grade},
                                    money_limit=#{customer.moneyLimit},address= #{customer.address},
                                    contact=#{customer.contact},phone=#{customer.phone} where id=#{customer.id}
    </update>
    <delete id="deleteCustomer" >
        delete from sd.customer  where id=#{customer.id}
    </delete>
    <select id="exportSelectCustomerDeliveryDate" >
        select d.delivery_id,
               dd.order_id,
               d.customer_name,
               d.project,
               od.product_name,
               sum(dd.quantity)    as quantity,
               sum(dd.area)        as area,
               dd.price,
               sum(dd.money)       as money,
               date(d.create_time) as create_time
        from sd.delivery_detail dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.order_detail od on od.order_id = dd.order_id and od.order_number = dd.order_number
        where date(d.create_time) >= #{startDate}
          and date(d.create_time) &lt;= #{endDate}
          and d.customer_id = #{orderDetail.order.customerId}
        group by od.order_id,od.product_id
        UNION ALL
        select d.delivery_id,
               o.order_id,
               d.customer_name,
               d.project,
               bom.alias           as product_name,
               sum(om.quantity)    as quantity,
               0                   as area,
               om.price,
               sum(om.money)       as money,
               date(d.create_time) as create_time
        from (select * from sd.delivery_detail group by order_id) as dd
                 left join sd.delivery d on d.delivery_id = dd.delivery_id
                 left join sd.`order` o on o.order_id = dd.order_id
                 left join sd.order_other_money om on om.order_id = o.order_id
                 left join sd.basic_other_money bom on bom.`column` = om.`column`
        where date(d.create_time) >= #{startDate}
          and date(d.create_time) &lt;= #{endDate}
          and d.customer_id = #{orderDetail.order.customerId}
          and om.money is not null
        group by d.delivery_id, o.order_id, om.`column`
        UNION ALL
        select d.delivery_id,
               d.order_id,
               d.customer_name,
               d.project,
               '运费'           as product_name,
               d.freight_quantity    as quantity,
               0                   as area,
               d.freight_price    as price,
               d.freight        as money,
               date(d.create_time) as create_time
        from sd.delivery d
        where date(d.create_time) >= #{startDate}
          and date(d.create_time) &lt;= #{endDate}
          and d.customer_id = #{orderDetail.order.customerId}
          and d.freight >0
        group by d.delivery_id
    </select>
    <select id="exportSelectCustomerOderDate" >
        select od.order_id,
               o.project,
               od.product_name,
               o.customer_name,
               sum(od.quantity)     as quantity,
               sum(od.compute_gross_area)         as area,
               od.price,
               sum(od.gross_amount) as money,
               date(o.create_time)  as create_time
        from order_detail od
                 left join `order` o on o.order_id = od.order_id
        where date(o.create_time) >= #{startDate}
          and date(o.create_time) &lt;= #{endDate}
          and o.customer_id = #{orderDetail.order.customerId}
          and o.create_order>0
        group by od.order_id,od.product_id
        UNION ALL
        select o.order_id,
               o.project,
               bom.alias           as product_name,
               o.customer_name,
               sum(om.quantity)    as quantity,
               0                   as area,
               om.price,
               sum(om.money)       as money,
               date(o.create_time) as create_time
        from `order` o
                 left join sd.order_other_money om on om.order_id = o.order_id
                 left join sd.basic_other_money bom on bom.`column` = om.`column`
        where date(o.create_time) >= #{startDate}
          and date(o.create_time) &lt;= #{endDate}
          and o.customer_id = #{orderDetail.order.customerId}
          and om.money is not null
        group by o.order_id, om.`column`
    </select>
</mapper>