Newer
Older
casic-metering / casic-metering-dao / src / main / resources / mapper / business / BusinessOrderMapper.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.casic.missiles.mapper.business.BusinessOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.business.BusinessOrder">
        <id column="id" property="id" />
        <result column="order_code" property="orderCode" />
        <result column="order_type" property="orderType" />
        <result column="order_time" property="orderTime" />
        <result column="deliverer_id" property="delivererId" />
        <result column="deliverer" property="deliverer" />
        <result column="deliverer_tel" property="delivererTel" />
        <result column="fixed_tel" property="fixedTel" />
        <result column="email" property="email" />
        <result column="invoice_company" property="invoiceCompany" />
        <result column="contact_return" property="contactReturn" />
        <result column="direct_return" property="directReturn" />
        <result column="need_accord_declare" property="needAccordDeclare" />
        <result column="need_advice" property="needAdvice" />
        <result column="accord_lab" property="accordLab" />
        <result column="agree_other" property="agreeOther" />
        <result column="time_require" property="timeRequire" />
        <result column="staff_no" property="staffNo" />
        <result column="staff_name" property="staffName" />
        <result column="receive_date" property="receiveDate" />
        <result column="deliver_time" property="deliverTime" />
        <result column="plan_deliver_time" property="planDeliverTime" />
        <result column="require_over_time" property="requireOverTime" />
        <result column="customer_id" property="customerId" />
        <result column="certification_company" property="certificationCompany" />
        <result column="certification_company_address" property="certificationCompanyAddress" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="minio_file_name" property="minioFileName" />
        <result column="certifications" property="certifications" />
        <result column="is_urgent" property="isUrgent" />
        <result column="is_del" property="isDel" />
        <result column="create_user" property="createUser" />
        <result column="bus_person_id" property="busPersonId" />
        <result column="bus_person_name" property="busPersonName" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, order_code, order_type, order_time, deliverer_id, deliverer, deliverer_tel, fixed_tel, email, invoice_company, contact_return, direct_return,
        need_accord_declare, need_advice, accord_lab, agree_other, staff_no, staff_name, receive_date, deliver_time, plan_deliver_time,
        require_over_time, customer_id, status, remark, minio_file_name, certifications, is_urgent, is_del, create_user, bus_person_id, bus_person_name,
        create_time, update_time
    </sql>

    <select id="selectIdsByStatus" resultType="java.lang.Long">
        SELECT id
        FROM business_order
        WHERE is_del = 0 AND status = #{orderStatus}
    </select>

    <select id="ordersToday" resultType="java.lang.Integer">
        SELECT COUNT(id) AS orders
        FROM business_order
        WHERE is_del = 0 AND DATE(create_time) = CURDATE()
    </select>

    <select id="ordersThisYear" resultType="java.lang.Integer">
        SELECT COUNT(id) AS orders
        FROM business_order
        WHERE is_del = 0 AND YEAR(create_time) = YEAR(NOW())
    </select>

    <select id="ordersThisMonth" resultType="java.lang.Integer">
        SELECT COUNT(id) AS orders
        FROM business_order
        WHERE is_del = 0 AND DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
    </select>

    <select id="selectOrderForCockpit" resultType="com.casic.missiles.model.business.BusinessOrder">
        SELECT *
        FROM business_order
        WHERE is_del = 0
        AND (status = 2 OR status = 4)
        ORDER BY create_time DESC
    </select>

    <select id="selectOrderCityRank" resultType="com.casic.missiles.dto.cockpit.CityTopResponse">
        SELECT ci.address_city_name AS cityName, COUNT(case when certifications=1 then 1 end) AS orderCount, COUNT(case when certifications=2 then 1 end) AS calibrationOrderCount
        FROM business_order bo
        JOIN customer_info ci ON bo.customer_id = ci.id
        WHERE bo.is_del = 0
        GROUP BY ci.address_city_name
        HAVING ci.address_city_name IS NOT NULL
        ORDER BY orderCount + calibrationOrderCount
    </select>

    <select id="selectPreMonthCountByYear" resultType="com.casic.missiles.dto.cockpit.BusTrendResponse">
        SELECT DATE_FORMAT(order_time,'%Y-%m') AS dimension, COUNT(id) AS orderCount
        FROM business_order
        WHERE is_del = 0
        AND DATE_SUB(CURDATE(), INTERVAL 365 DAY) &lt;= DATE(order_time)
        GROUP BY DATE_FORMAT(order_time,'%Y-%m')
    </select>

    <select id="selectDetailById" resultMap="BaseResultMap">
        SELECT bo.*, ci.postal_code
        FROM business_order bo
        JOIN customer_info ci ON bo.customer_id = ci.id
        WHERE bo.id = #{id}
    </select>

    <select id="selectMaxOrderNoByDate" resultType="java.lang.Long">
        SELECT IFNULL(max(RIGHT(order_code, 12)), 0)
        FROM business_order
        WHERE order_code LIKE concat('%',#{datePrefix},'%')
        LIMIT 1;
    </select>
</mapper>