unis_sip/ruoyi-sip/src/main/resources/mapper/manage/OrderInfoMapper.xml

396 lines
18 KiB
XML

<?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.ruoyi.sip.mapper.OrderInfoMapper">
<resultMap type="OrderInfo" id="OrderInfoResult">
<result property="id" column="id"/>
<result property="projectCode" column="project_code"/>
<result property="orderCode" column="order_code"/>
<result property="versionCode" column="version_code"/>
<result property="orderName" column="order_name"/>
<result property="customerName" column="customer_name"/>
<result property="customerCode" column="customer_code"/>
<result property="customerContact" column="customer_contact"/>
<result property="customerPhone" column="customer_phone"/>
<result property="customerEmail" column="customer_email"/>
<result property="orderType" column="order_type"/>
<result property="orderAgentCode" column="order_agent_code"/>
<result property="orderPartnerCode" column="order_partner_code"/>
<result property="bgType" column="bg_type"/>
<result property="orderDate" column="order_date"/>
<result property="status" column="status"/>
<result property="remark" column="remark"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
<result property="deletedAt" column="deleted_at"/>
</resultMap>
<resultMap id="OrderInfoOrderListResult" type="OrderInfo" extends="OrderInfoResult">
<collection property="orderListList" ofType="OrderList" column="id" select="selectOrderListList"/>
</resultMap>
<resultMap type="OrderList" id="OrderListResult">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="productCode" column="product_code"/>
<result property="quantity" column="quantity"/>
<result property="price" column="price"/>
<result property="amount" column="amount"/>
<result property="remark" column="remark"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
<result property="deletedAt" column="deleted_at"/>
</resultMap>
<resultMap type="OrderList" id="OrderListProductResult">
<result property="id" column="id"/>
<result property="orderId" column="order_id"/>
<result property="productCode" column="product_code"/>
<result property="quantity" column="quantity"/>
<result property="price" column="price"/>
<result property="amount" column="amount"/>
<result property="remark" column="remark"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
<result property="deletedAt" column="deleted_at"/>
<association property="productInfo" javaType="com.ruoyi.sip.domain.ProductInfo">
<result property="id" column="id"/>
<result property="productCode" column="product_code"/>
<result property="productName" column="product_name"/>
<result property="model" column="model"/>
<result property="type" column="type"/>
<result property="value" column="value"/>
<result property="description" column="description"/>
<result property="remark" column="remark"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
<result property="deletedAt" column="deleted_at"/>
</association>
</resultMap>
<sql id="selectOrderInfoVo">
select id,
project_code,
order_code,
version_code,
order_name,
customer_code,
customer_name,
customer_contact,
customer_phone,
customer_email,
customer_address,
industry_type,
customer_postcode,
order_type,
order_agent_code,
order_partner_code,
bg_type,
order_date,
status,
remark,
created_at,
updated_at,
deleted_at
from order_info
</sql>
<select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
select t1.id,
t1.project_code,
t1.order_code,
t1.version_code,
t1.order_name,
t1.customer_code,
t1.customer_name,
t1.customer_contact,
t1.customer_phone,
t1.customer_email,
t1.customer_address,
t1.industry_type,
t1.customer_postcode,
t1.order_type,
t1.order_agent_code,
t1.order_partner_code,
t1.bg_type,
t1.order_date,
t1.status,
t1.remark,
t1.created_at,
t1.updated_at,
t1.deleted_at,
t1.create_by,
t1.update_by,
t2.user_name as create_by_name
from order_info t1
left join sys_user t2 on t1.create_by=t2.user_id
<where>
and t1.status=0
<if test="orderCode != null and orderCode != ''">and t1.order_code like concat('%', #{orderCode}, '%')</if>
<if test="orderName != null and orderName != ''">and t1.order_name like concat('%', #{orderName}, '%')</if>
<if test="customerName != null and customerName != ''">and t1.customer_name like concat('%', #{customerName},
'%')
</if>
<if test="orderType != null and orderType != ''">and t1.order_type = #{orderType}</if>
<choose>
<when test="updatedAtStart!=null and updatedAtEnd!=null">
and t1.updated_at between #{updatedAtStart} and #{updatedAtEnd}
</when>
<when test="updatedAtStart!=null">
and t1.updated_at <![CDATA[ >= ]]> #{updatedAtStart}
</when>
<when test="updatedAtEnd!=null">
and t1.updated_at <![CDATA[ <= ]]> #{updatedAtEnd}
</when>
</choose>
<if test="serialNumber!=null and serialNumber!=''">
and t1.id in (SELECT order_id from order_delivery where id in (
select delivery_id from delivery_list where serial_number=#{serialNumber}))
</if>
</where>
</select>
<select id="selectOrderInfoById" parameterType="Long" resultMap="OrderInfoOrderListResult">
select t1.id,
t1.project_code,
t1.order_code,
t1.version_code,
t1.order_name,
t1.customer_name,
t1.customer_code,
t1.customer_address,
t1.customer_postcode,
t1.customer_contact,
t1.customer_phone,
t1.customer_email,
t1.order_type,
t1.order_agent_code,
t1.order_partner_code,
t1.order_date,
t1.status,
t1.remark,
t1.created_at,
t1.updated_at,
t1.deleted_at,
t2.agent_name as order_agent_name,
t3.partner_name as order_partner_name
from order_info t1
left join agent_info t2 on t1.order_agent_code = t2.agent_code
left join partner_info t3 on t1.order_partner_code=t3.partner_code
where t1.id = #{id}
</select>
<select id="selectOrderListList" resultMap="OrderListResult">
select t1.id,
t1.order_id,
t1.product_code,
t2.product_name,
t1.quantity,
t1.discount,
t1.price,
t1.amount,
t1.remark,
t1.created_at,
t1.updated_at,
t1.deleted_at
from order_list t1
left join product_info t2 on t1.product_code=t2.product_code
where t1.order_id = #{order_id}
and t1.status=0
</select>
<select id="listOrderListByDeliveryId" resultMap="OrderListResult">
select id,
order_id,
product_code,
quantity,
price,
amount,
remark,
created_at,
updated_at,
deleted_at
from order_list
where order_id = (select order_id from order_delivery where id = #{deliveryId} and status=0)
and status=0
</select>
<select id="selectOrderInfoByMaintenance" resultType="com.ruoyi.sip.domain.OrderInfo">
<include refid="selectOrderInfoVo"/>
where status=0
<if test="serialNumber!=null and serialNumber!=''">
and id in (
select t2.order_id from delivery_list t1 left join order_delivery t2 on t1.delivery_id =t2.id where
t1.serial_number=#{serialNumber})
</if>
<if test="productCode!=null and productCode!=''">
and id in (
select t2.order_id from delivery_list t1 left join order_delivery t2 on t1.delivery_id =t2.id where
t1.product_code=#{productCode})
</if>
</select>
<select id="listMaintenanceByOrderIdList" resultMap="OrderListProductResult">
SELECT
t1.*,t2.*
FROM
order_list t1
inner join product_info t2 on t1.product_code=t2.product_code and t2.type in (11,22)
WHERE
t1.order_id IN
<foreach collection="list" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<select id="listExport" resultType="com.ruoyi.sip.domain.OrderList">
select id, order_id, product_code, quantity, price, amount,discount,remark, created_at, updated_at
from order_list
<where>
<if test="id!=null">
and id=#{id}
</if>
<if test="orderId!=null">
and order_id=#{orderId}
</if>
<if test="productCode!=null and productCode!=''">
and product_code=#{productCode}
</if>
</where>
</select>
<select id="selectUniqueCount" resultType="java.lang.Integer">
select count(1) from order_info where order_code = #{orderCode} and version_code=#{versionCode} and status=0
<if test="id != null">and id != #{id}</if>
</select>
<insert id="insertOrderInfo" parameterType="OrderInfo" useGeneratedKeys="true" keyProperty="id">
insert into order_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="projectCode != null">project_code,</if>
<if test="orderCode != null and orderCode != ''">order_code,</if>
<if test="versionCode != null">version_code,</if>
<if test="orderName != null and orderName != ''">order_name,</if>
<if test="customerName != null and customerName != ''">customer_name,</if>
<if test="customerCode != null and customerCode != ''">customer_code,</if>
<if test="customerAddress != null and customerAddress != ''">customer_address,</if>
<if test="customerPostcode != null and customerPostcode != ''">customer_postcode,</if>
<if test="customerContact != null">customer_contact,</if>
<if test="customerPhone != null">customer_phone,</if>
<if test="customerEmail != null">customer_email,</if>
<if test="orderType != null">order_type,</if>
<if test="orderAgentCode != null">order_agent_code,</if>
<if test="orderPartnerCode != null">order_partner_code,</if>
<if test="orderDate != null">order_date,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
created_at,updated_at,create_by,status
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="projectCode != null">#{projectCode},</if>
<if test="orderCode != null and orderCode != ''">#{orderCode},</if>
<if test="versionCode != null">#{versionCode},</if>
<if test="orderName != null and orderName != ''">#{orderName},</if>
<if test="customerName != null and customerName != ''">#{customerName},</if>
<if test="customerCode != null and customerCode != ''">#{customerCode},</if>
<if test="customerAddress != null and customerAddress != ''">#{customerAddress},</if>
<if test="customerPostcode != null and customerPostcode != ''">#{customerPostcode},</if>
<if test="customerContact != null">#{customerContact},</if>
<if test="customerPhone != null">#{customerPhone},</if>
<if test="customerEmail != null">#{customerEmail},</if>
<if test="orderType != null">#{orderType},</if>
<if test="orderAgentCode != null">#{orderAgentCode},</if>
<if test="orderPartnerCode != null">#{orderPartnerCode},</if>
<if test="orderDate != null">#{orderDate},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
NOW(),now(),#{createBy},0
</trim>
</insert>
<update id="updateOrderInfo" parameterType="OrderInfo">
update order_info
<trim prefix="SET" suffixOverrides=",">
<if test="projectCode != null">project_code = #{projectCode},</if>
<if test="orderCode != null and orderCode != ''">order_code = #{orderCode},</if>
<if test="versionCode != null">version_code = #{versionCode},</if>
<if test="orderName != null and orderName != ''">order_name = #{orderName},</if>
<if test="customerName != null and customerName != ''">customer_name = #{customerName},</if>
<if test="customerContact != null">customer_contact = #{customerContact},</if>
<if test="customerPhone != null">customer_phone = #{customerPhone},</if>
<if test="customerEmail != null">customer_email = #{customerEmail},</if>
<if test="customerCode != null and customerCode != ''">customer_code=#{customerCode},</if>
<if test="customerAddress != null and customerAddress != ''">customer_address=#{customerAddress},</if>
<if test="customerPostcode != null and customerPostcode != ''">customer_postcode=#{customerPostcode},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="orderAgentCode != null">order_agent_code = #{orderAgentCode},</if>
<if test="orderPartnerCode != null">order_partner_code = #{orderPartnerCode},</if>
<if test="orderDate != null">order_date = #{orderDate},</if>
<if test="status != null">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
updated_at = NOW(),update_by = #{updateBy}
</trim>
where id = #{id}
</update>
<update id="logicRemoveListById">
update order_list set deleted_at=NOW(), status=1 where id in
<foreach item="item" index="index" collection="list" open="(" close=")" separator=",">
#{item.id}
</foreach>
</update>
<update id="updateListBatch">
<foreach item="item" index="index" collection="list" separator=";">
update order_list
<trim prefix="SET" suffixOverrides=",">
<if test="item.quantity != null">quantity = #{item.quantity},</if>
<if test="item.amount != null">amount = #{item.amount},</if>
<if test="item.discount != null and item.discount!=''">discount = #{item.discount},</if>
<if test="item.price != null and item.price!=''">price = #{item.price},</if>
<if test="item.remark != null">remark = #{item.remark},</if>
updated_at = NOW(),update_by = #{item.updateBy}
</trim>
where id = #{item.id}
</foreach>
</update>
<delete id="deleteOrderInfoById" parameterType="Long">
update order_info
set deleted_at=NOW(),
updated_at=now(),
status=1
where id = #{id}
</delete>
<delete id="deleteOrderInfoByIds" parameterType="String">
update order_info set deleted_at=NOW(), updated_at=NOW(), status=1 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteOrderListByOrderIds" parameterType="String">
update order_list set status=1, deleted_at=now() where order_id in
<foreach item="orderId" collection="array" open="(" separator="," close=")">
#{orderId}
</foreach>
</delete>
<delete id="deleteOrderListByOrderId" parameterType="Long">
delete
from order_list
where order_id = #{orderId}
</delete>
<delete id="deleteOrderListById">
delete from order_list where id in
<foreach item="item" index="index" collection="list" separator="," open="(" close=")">
#{item}
</foreach>
</delete>
<insert id="batchOrderList">
insert into order_list(id , order_id, product_code, quantity, price, amount,discount,remark, created_at, updated_at,create_by) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.id}, #{item.orderId}, #{item.productCode}, #{item.quantity}, #{item.price}, #{item.amount},#{item.discount},
#{item.remark}, now(),now(),#{item.createBy})
</foreach>
</insert>
</mapper>