<!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="getSelectCustomerOderDate" resultMap="selectCustomerOrderDetail">
|
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.area) as area,
|
od.shape,
|
od.width,
|
od.height,
|
o.batch,
|
o.money,
|
o.order_type,
|
o.salesman,
|
o.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) <= #{endDate}
|
<if test="orderDetail.order.customerId != null and orderDetail.order.customerId != ''">
|
and o.customer_id = #{orderDetail.order.customerId}
|
</if>
|
<if test="orderDetail.order.project != null and orderDetail.order.project != ''">
|
and o.project regexp #{orderDetail.order.project}
|
</if>
|
<if test="orderDetail.order.batch != null and orderDetail.order.batch != ''">
|
and o.batch regexp #{orderDetail.order.batch}
|
</if>
|
<if test="orderDetail.order.money != null and orderDetail.order.money != ''">
|
and o.money regexp REGEXP_REPLACE(#{orderDetail.order.money},'\\.0+$','')
|
</if>
|
<if test="orderDetail.order.orderType != null and orderDetail.order.orderType != ''">
|
and o.order_type regexp #{orderDetail.order.orderType}
|
</if>
|
<if test="orderDetail.order.salesman != null and orderDetail.order.salesman != ''">
|
and o.salesman regexp #{orderDetail.order.salesman}
|
</if>
|
<if test="orderDetail.orderId != null and orderDetail.orderId != ''">
|
and od.order_id regexp #{orderDetail.orderId}
|
</if>
|
<if test="orderDetail.orderNumber != null and orderDetail.orderNumber != ''">
|
and od.order_number regexp #{orderDetail.orderNumber}
|
</if>
|
<if test="orderDetail.productId != null and orderDetail.productId != ''">
|
and od.product_id regexp #{orderDetail.productId}
|
</if>
|
<if test="orderDetail.productName != null and orderDetail.productName != ''">
|
and od.product_name regexp #{orderDetail.productName}
|
</if>
|
<if test="orderDetail.shape != null and orderDetail.shape != ''">
|
and od.shape regexp #{orderDetail.shape}
|
</if>
|
<if test="orderDetail.width != null and orderDetail.width != ''">
|
and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
|
</if>
|
<if test="orderDetail.height != null and orderDetail.height != ''">
|
and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
|
</if>
|
|
</where>
|
group by od.product_id, od.width, od.height
|
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) <= #{endDate}
|
<if test="orderDetail.order.customerId != null and orderDetail.order.customerId != ''">
|
and o.customer_id = #{orderDetail.order.customerId}
|
</if>
|
<if test="orderDetail.order.project != null and orderDetail.order.project != ''">
|
and o.project regexp #{orderDetail.order.project}
|
</if>
|
<if test="orderDetail.order.batch != null and orderDetail.order.batch != ''">
|
and o.batch regexp #{orderDetail.order.batch}
|
</if>
|
<if test="orderDetail.order.money != null and orderDetail.order.money != ''">
|
and o.money regexp REGEXP_REPLACE(#{orderDetail.order.money},'\\.0+$','')
|
</if>
|
<if test="orderDetail.order.orderType != null and orderDetail.order.orderType != ''">
|
and o.order_type regexp #{orderDetail.order.orderType}
|
</if>
|
<if test="orderDetail.order.salesman != null and orderDetail.order.salesman != ''">
|
and o.salesman regexp #{orderDetail.order.salesman}
|
</if>
|
<if test="orderDetail.orderId != null and orderDetail.orderId != ''">
|
and od.order_id regexp #{orderDetail.orderId}
|
</if>
|
<if test="orderDetail.orderNumber != null and orderDetail.orderNumber != ''">
|
and od.order_number regexp #{orderDetail.orderNumber}
|
</if>
|
<if test="orderDetail.productId != null and orderDetail.productId != ''">
|
and od.product_id regexp #{orderDetail.productId}
|
</if>
|
<if test="orderDetail.productName != null and orderDetail.productName != ''">
|
and od.product_name regexp #{orderDetail.productName}
|
</if>
|
<if test="orderDetail.shape != null and orderDetail.shape != ''">
|
and od.shape regexp #{orderDetail.shape}
|
</if>
|
<if test="orderDetail.width != null and orderDetail.width != ''">
|
and od.width regexp REGEXP_REPLACE(#{orderDetail.width},'\\.0+$','')
|
</if>
|
<if test="orderDetail.height != null and orderDetail.height != ''">
|
and od.height regexp REGEXP_REPLACE(#{orderDetail.height},'\\.0+$','')
|
</if>
|
|
</where>
|
group by od.product_id, od.width, od.height) 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.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,grade,money_limit,address,contact,phone)
|
values (
|
#{customer.customerName},#{customer.grade},#{customer.moneyLimit},
|
#{customer.address},#{customer.contact},#{customer.phone}
|
)
|
</insert>
|
|
<update id="updateCustomer" useGeneratedKeys="true" >
|
update sd.customer set customer_name=#{customer.customerName},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>
|
</mapper>
|