123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014 |
- <?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.fjhx.contract.mapper.ContractMapper">
- <resultMap id="contractResultMap" type="com.fjhx.contract.entity.Contract">
- <id column="id" property="id"/>
- <result column="code" property="code"/>
- <result column="invoice_code" property="invoiceCode"/>
- <result column="customer_id" property="customerId"/>
- <result column="customer_name" property="customerName"/>
- <result column="customer_lastname" property="customerLastname"/>
- <result column="customer_second_name" property="customerSecondName"/>
- <result column="customer_company_name" property="customerCompanyName"/>
- <result column="customer_country_id" property="customerCountryId"/>
- <result column="customer_country_name" property="customerCountryName"/>
- <result column="customer_state" property="customerState"/>
- <result column="customer_city_id" property="customerCityId"/>
- <result column="customer_city_name" property="customerCityName"/>
- <result column="customer_addr" property="customerAddr"/>
- <result column="customer_tel" property="customerTel"/>
- <result column="customer_zip_code" property="customerZipCode"/>
- <result column="customer_po" property="customerPo"/>
- <result column="customer_other_msg" property="customerOtherMsg"/>
- <result column="longitude" property="longitude"/>
- <result column="latitude" property="latitude"/>
- <result column="company_id" property="companyId"/>
- <result column="company_bank_id" property="companyBankId"/>
- <result column="company_bank_name" property="companyBankName"/>
- <result column="company_bank_card" property="companyBankCard"/>
- <result column="company_bank_swift_code" property="companyBankSwiftCode"/>
- <result column="company_bank_addr" property="companyBankAddr"/>
- <result column="company_bank_type" property="companyBankType"/>
- <result column="coll_name" property="collName"/>
- <result column="coll_address" property="collAddress"/>
- <result column="pay_way" property="payWay"/>
- <result column="pre_pay_ratio" property="prePayRatio"/>
- <result column="transfer_bank_name" property="transferBankName"/>
- <result column="transfer_bank_swift_code" property="transferBankSwiftCode"/>
- <result column="trade_mode_id" property="tradeModeId"/>
- <result column="payment_id" property="paymentId"/>
- <result column="payment_remark" property="paymentRemark"/>
- <result column="valid_time" property="validTime"/>
- <result column="delivery_day" property="deliveryDay"/>
- <result column="shipping_type" property="shippingType"/>
- <result column="express_id" property="expressId"/>
- <result column="wharf" property="wharf"/>
- <result column="currency_type" property="currencyType"/>
- <result column="contract_price" property="contractPrice"/>
- <result column="contract_price_en" property="contractPriceEn"/>
- <result column="status" property="status"/>
- <result column="approved_date" property="approvedDate"/>
- <result column="confirm_date" property="confirmDate"/>
- <result column="warranty_day" property="warrantyDay"/>
- <result column="join_type" property="joinType"/>
- <result column="join_id" property="joinId"/>
- <result column="process_instance_id" property="processInstanceId"/>
- <result column="process_instance_name" property="processInstanceName"/>
- <result column="process_instance_user_id" property="processInstanceUserId"/>
- <result column="process_instance_user_name" property="processInstanceUserName"/>
- <result column="source" property="source"/>
- <result column="remark" property="remark"/>
- <result column="is_change" property="isChange"/>
- <result column="change_cost" property="changeCost"/>
- <result column="change_cost2" property="changeCost2"/>
- <result column="change_cost3" property="changeCost3"/>
- <result column="change_remark" property="changeRemark"/>
- <result column="pre_contract_id" property="preContractId"/>
- <result column="version" property="version"/>
- <result column="data_type" property="dataType"/>
- <result column="action_type" property="actionType"/>
- <result column="contract_sample_confirm" property="contractSampleConfirm"/>
- <result column="tax_rate" property="taxRate"/>
- <result column="is_complete" property="isComplete"/>
- <result column="create_user" property="createUser"/>
- <result column="create_time" property="createTime"/>
- <result column="update_user" property="updateUser"/>
- <result column="update_time" property="updateTime"/>
- <!-- 扩展字段 -->
- <result column="create_user_name" property="createUserName"/>
- <result column="create_date" property="createDate"/>
- <result column="order_count" property="orderCount"/>
- <result column="sumContractPrice" property="sumContractPrice"/>
- <result column="sumOrder" property="sumOrder"/>
- <result column="dayTime" property="dayTime"/>
- <result column="product_id" property="productId"/>
- </resultMap>
- <sql id="sqlField">
- SELECT * FROM t_erp_contract
- </sql>
- <select id="getList" resultMap="contractResultMap">
- SELECT
- t1.id,
- t1.type,
- t1.`code`,
- t1.`status`,
- t1.version,
- t1.source,
- t1.create_time,
- t1.customer_id,
- t1.customer_company_name,
- t1.customer_name,
- t1.contract_price,
- t1.currency_type,
- t1.is_change,
- t1.contract_sample_confirm,
- t1.process_instance_id,
- t1.is_complete,
- t1.company_id,
- t2.real_name AS create_user_name
- FROM
- t_erp_contract t1
- LEFT JOIN blade_user t2 ON t1.create_user = t2.id
- <include refid="getListCondition" />
- <!-- 列表类型,1:外销合同管理列表、2:邮件-右侧外销合同列表、3:成单样品合同列表、4:到账认领选择合同、5:邮件-右侧成单样品合同列表 -->
- <choose>
- <when test="listType neq null and (listType eq 1 or listType eq 3 or listType eq 4)">
- ORDER BY
- t1.code DESC
- </when>
- <otherwise>
- ORDER BY
- t1.create_time DESC
- </otherwise>
- </choose>
- <include refid="Sql.sql_limit" />
- </select>
- <select id="getListCount" resultType="java.lang.Integer">
- SELECT
- COUNT(*) AS c
- FROM
- t_erp_contract t1
- LEFT JOIN blade_user t2 ON t1.create_user = t2.id
- <include refid="getListCondition" />
- </select>
- <sql id="getListCondition">
- <where>
- t1.tenant_id = #{tenantId}
- <!-- 列表类型,1:外销合同管理列表、2:邮件-右侧外销合同列表、3:成单样品合同列表、4:到账认领选择合同、5:邮件-右侧成单样品合同列表 -->
- <!-- data_type数据类型,0:外销合同、1:成单样品 -->
- <choose>
- <when test="listType neq null and (listType eq 1 or listType eq 2)">
- AND t1.data_type = 0
- </when>
- <when test="listType neq null and (listType eq 3 or listType eq 5)">
- AND t1.data_type = 1
- </when>
- <when test="listType neq null and listType eq 4">
- <!-- 未确认 and 未结清 -->
- <![CDATA[ AND t1.`status` >= 30 AND t1.`status` <= 110 ]]>
- <!-- 是否处于变更中,0、不存在变更;1:本身为变更数据(表示从元数据被发起变更后的新数据);2:存在变更数据(表示元数据被发起变更) -->
- AND t1.is_change IN(0, 2)
- </when>
- </choose>
- <choose>
- <when test="listType neq null and listType eq 2">
- AND t1.status != 999
- <!-- 是否处于变更中,0、不存在变更;1:本身为变更数据(表示从元数据被发起变更后的新数据);2:存在变更数据(表示元数据被发起变更) -->
- AND t1.is_change IN(0, 2)
- </when>
- <otherwise>
- AND t1.status != 999
- </otherwise>
- </choose>
- <if test="userId neq null and userId neq ''">
- AND t1.create_user = #{userId}
- </if>
- <if test="status neq null and status neq ''">
- AND t1.status = #{status}
- </if>
- <!-- 钉钉使用 -->
- <if test="statusRange neq null and statusRange neq ''">
- AND t1.status >= #{statusRange}
- </if>
- <if test="source neq null and source neq ''">
- AND t1.source = #{source}
- </if>
- <if test="code neq null and code neq ''">
- AND (INSTR(t1.`code`, #{code}) > 0)
- </if>
- <if test="customerCompanyName neq null and customerCompanyName neq ''">
- AND (INSTR(t1.customer_company_name, #{customerCompanyName}) > 0)
- </if>
- <if test="customerName neq null and customerName neq ''">
- AND (INSTR(t1.customer_name, #{customerName}) > 0)
- </if>
- <if test="createUserName neq null and createUserName neq ''">
- AND (
- INSTR(t2.`name`, #{createUserName}) > 0
- OR
- INSTR(t2.real_name, #{createUserName}) > 0
- )
- </if>
- <if test="keyWord neq null and keyWord neq ''">
- AND (
- INSTR(t1.`code`, #{keyWord}) > 0
- OR
- INSTR(t1.customer_company_name, #{keyWord}) > 0
- )
- </if>
- <if test="customerIds neq null and customerIds.size() > 0">
- <foreach collection="customerIds" item="customerId" open="AND t1.customer_id IN (" separator=","
- close=")">
- #{customerId}
- </foreach>
- </if>
- <if test="customerId neq null and customerId neq ''">
- AND t1.customer_id = #{customerId}
- </if>
- <!-- 关联类型(制作合同时使用),1:关联成单样品 -->
- <if test="joinType neq null and joinType eq 1">
- <!-- 排除已被关联的数据 -->
- AND NOT EXISTS (
- SELECT
- 1
- FROM
- t_erp_contract t3
- <where>
- t3.tenant_id = #{tenantId}
- AND t3.join_id = t1.id
- </where>
- )
- </if>
- <!-- 日历统计使用 -->
- <if test="beginDate neq null and beginDate neq '' and endDate neq null and endDate neq ''">
- <if test="listType neq null and listType eq 1">
- AND t1.`status` >= 30
- <![CDATA[ AND t1.`status` < 110 ]]>
- </if>
- AND EXISTS (
- SELECT
- 1
- FROM
- t_erp_shipment_detailed t3
- WHERE
- t1.id = t3.business_id
- AND DATE_FORMAT( t3.shipment_time, '%Y-%m-%d' ) >= #{beginDate}
- <![CDATA[ AND DATE_FORMAT( t3.shipment_time, '%Y-%m-%d' ) <= #{endDate} ]]>
- )
- </if>
- <!-- 数据看板 二级清单 -->
- <if test="ids neq null and ids.size > 0">
- AND t1.id IN
- <foreach collection="ids" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="isComplete neq null and isComplete neq ''">
- AND t1.is_complete = #{isComplete}
- </if>
- <if test="type neq null and type neq ''">
- AND t1.type=#{type}
- </if>
- </where>
- </sql>
- <update id="updateStatusById">
- UPDATE t_erp_contract
- <set>
- <if test="status neq null">status = #{status},</if>
- <if test="updateUser neq null">update_user = #{updateUser},</if>
- update_time = NOW()
- </set>
- <where>
- id IN
- <foreach collection="ids" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- <!-- 合同状态如果走到后面不允许回滚到前面的状态,com.ruoyi.common.enums.ContractStatusEnum -->
- <![CDATA[
- AND `status` < #{status}
- ]]>
- </where>
- </update>
- <select id="getNextVersionByCode" resultType="java.lang.Integer">
- SELECT
- MAX(t1.version) AS version
- FROM
- t_erp_contract t1
- <where>
- <!-- 有效的合同 -->
- t1.`status` != 999
- AND t1.`code` = #{code}
- </where>
- </select>
- <!-- 客户画像:销售分析列表 -->
- <select id="getSalesAnalysisList" resultMap="contractResultMap">
- SELECT
- <!-- 时间条件类型:非年度查询 -->
- <if test="timeConditionType eq 0">
- DATE_FORMAT( create_time, '%Y-%m-%d' ) create_date,
- </if>
- <!-- 时间条件类型:年度查询 -->
- <if test="timeConditionType eq 1">
- DATE_FORMAT( create_time, '%Y-%m' ) create_date,
- </if>
- count( id ) order_count,
- SUM( contract_price ) contract_price
- FROM
- t_erp_contract
- <!-- 客户画像:销售分析列表条件 -->
- <include refid="getSalesAnalysisListCondition" />
- ORDER BY
- create_time ASC
- <include refid="Sql.sql_limit" />
- </select>
- <!-- 客户画像:销售分析列表总数 -->
- <select id="getSalesAnalysisListCount" resultType="java.lang.Integer">
- SELECT
- count(*) count
- FROM
- (
- SELECT
- DATE_FORMAT( create_time, '%Y-%m-%d' ) create_date
- FROM
- t_erp_contract
- <!-- 客户画像:销售分析列表条件 -->
- <include refid="getSalesAnalysisListCondition" />
- ) t
- </select>
- <!-- 客户画像:销售分析列表条件 -->
- <sql id="getSalesAnalysisListCondition">
- <where>
- customer_id = #{customerId}
- <!-- 时间条件类型:非年度查询 -->
- <if test="timeConditionType eq 0">
- <if test="startDate neq null and startDate neq ''">
- AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{startDate}
- </if>
- <if test="endDate neq null and endDate neq ''">
- <![CDATA[ AND DATE_FORMAT(create_time, '%Y-%m-%d') <= #{endDate} ]]>
- </if>
- </if>
- <!-- 时间条件类型:年度查询 -->
- <if test="timeConditionType eq 1">
- <if test="startDate neq null and startDate neq ''">
- AND DATE_FORMAT(create_time, '%Y-%m') >= #{startDate}
- </if>
- <if test="endDate neq null and endDate neq ''">
- <![CDATA[ AND DATE_FORMAT(create_time, '%Y-%m') <= #{endDate} ]]>
- </if>
- </if>
- </where>
- GROUP BY
- create_date
- </sql>
- <select id="getByCustomerId" resultMap="contractResultMap">
- SELECT
- t1.id,
- t1.`code`
- FROM
- t_erp_contract t1
- <where>
- t1.tenant_id = #{tenantId}
- AND t1.customer_id = #{customerId}
- </where>
- </select>
- <!--客户画像,销售统计柱状图-->
- <select id="getByCustomerIdAndDWM" resultMap="contractResultMap">
- SELECT
- t1.contract_price ,
- t1.create_time
- FROM
- t_erp_contract t1
- <include refid="getcondition"/>
- </select>
- <!--客户画像,售后合同下拉框-->
- <select id="getContractSelect" resultMap="contractResultMap">
- SELECT
- id,
- `code`
- FROM
- t_erp_contract
- WHERE
- customer_id = #{customerId}
- AND tenant_id = #{tenantId}
- AND `status` BETWEEN 20 AND 998
- </select>
- <!--客户画像,统计总销售额和订单数-->
- <select id="getByCustomerIdSumDWM" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
- count(1) as sumOrder
- FROM
- t_erp_contract t1
- <include refid="getcondition"/>
- </select>
- <!--客户画像,统计本周、本月、本年总销售额和订单数-->
- <select id="getByCustomerIdSumDayDWM" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
- count(1) as sumOrder,
- DATE_FORMAT(create_time,'%Y-%m-%d') as dayTime
- FROM
- t_erp_contract t1
- <include refid="getcondition"/>
- </select>
- <sql id="getcondition">
- <where>
- t1.tenant_id = #{tenantId}
- <if test="customerId neq null and customerId neq ''">
- AND t1.customer_id = #{customerId}
- </if>
- <choose>
- <!--本周-->
- <when test="type neq null and type neq '' and type eq 1 ">
- AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
- GROUP BY DATE_FORMAT(create_time,'%m-%d')
- </when>
- <!--本月-->
- <when test="type neq null and type neq '' and type eq 2 ">
- AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
- GROUP BY DATE_FORMAT(create_time,'%m-%d')
- </when>
- <!--本年-->
- <when test="type neq null and type neq '' and type eq 3 ">
- AND YEAR(create_time)=YEAR(NOW())
- GROUP BY DATE_FORMAT(create_time,'%Y-%m')
- </when>
- <otherwise>
- <if test="contractStartStr neq null and contractStartStr neq '' and
- contractEndStr neq null and contractEndStr neq ''">
- and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
- GROUP BY DATE_FORMAT(create_time,'%m-%d')
- </if>
- </otherwise>
- </choose>
- </where>
- </sql>
- <sql id="getSumCondition">
- <where>
- t1.tenant_id = #{tenantId}
- <choose>
- <!--本周-->
- <when test="type neq null and type neq '' and type eq 1 ">
- AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
- </when>
- <!--本月-->
- <when test="type neq null and type neq '' and type eq 2 ">
- AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
- </when>
- <!--本年-->
- <when test="type neq null and type neq '' and type eq 3 ">
- AND YEAR(create_time)=YEAR(NOW())
- </when>
- <otherwise>
- <if test="contractStartStr neq null and contractStartStr neq '' and
- contractEndStr neq null and contractEndStr neq ''">
- and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
- </if>
- </otherwise>
- </choose>
- </where>
- </sql>
- <!--外销合同-样品单查询-->
- <select id="getHuaXList" resultMap="contractResultMap">
- SELECT
- t1.id,
- t1.`code`,
- t1.`status`,
- t1.version,
- t1.source,
- t1.create_time,
- t1.customer_company_name,
- t1.customer_name,
- t1.contract_price,
- t1.currency_type,
- t1.is_change,
- t1.contract_sample_confirm,
- t1.process_instance_id,
- t2.real_name AS create_user_name
- FROM
- t_erp_contract t1
- LEFT JOIN blade_user t2 ON t1.create_user = t2.id
- <include refid="getListHuaXCondition" />
- <!-- 列表类型-1:外销合同管理列表 2:成单样品合同列表-->
- ORDER BY
- t1.code DESC
- <include refid="Sql.sql_limit" />
- </select>
- <!--外销合同-样品单条数查询-->
- <select id="getHuaXListCount" resultType="java.lang.Integer">
- SELECT
- COUNT(*) AS c
- FROM
- t_erp_contract t1
- LEFT JOIN blade_user t2 ON t1.create_user = t2.id
- <include refid="getListHuaXCondition" />
- </select>
- <sql id="getListHuaXCondition">
- <where>
- t1.tenant_id = #{tenantId}
- <if test="customerId neq null and customerId neq ''">
- AND t1.`customer_id` = #{customerId}
- </if>
- <!-- data_type数据类型,0:外销合同、1:成单样品 -->
- <if test="listType neq null and (listType eq 1)">
- AND t1.data_type = 0
- </if>
- <if test="listType neq null and (listType eq 3)">
- AND t1.data_type = 1
- </if>
- <if test="status neq null and status neq ''">
- AND t1.status = #{status}
- </if>
- <if test="createUserName neq null and createUserName neq ''">
- AND (
- INSTR(t2.`name`, #{createUserName}) > 0
- OR
- INSTR(t2.real_name, #{createUserName}) > 0
- )
- </if>
- <if test="contractStartStr neq null and contractStartStr neq '' and
- contractEndStr neq null and contractEndStr neq ''">
- and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
- </if>
- </where>
- </sql>
- <!--领导看板-统计总销售额-->
- <select id="getContractSumPrice" resultType="java.lang.String">
- SELECT
- CONVERT (
- IFNULL( SUM( t1.contract_price * t1.tax_rate ), 0 ),
- DECIMAL ( 10, 2 )) AS sumContractPrice
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- </select>
- <!--领导看板-统计下单数-->
- <select id="getContractSumOrder" resultType="java.lang.String">
- SELECT
- COUNT(1)
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- </select>
- <!--领导看板-下单客户数-->
- <select id="getContractSumCustomer" resultType="java.lang.Integer">
- SELECT
- COUNT(1)
- FROM(
- SELECT
- COUNT(1)
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- GROUP BY
- customer_id
- ) AS a
- </select>
- <!--领导看板-统计全球-获取经纬度坐标-->
- <select id="getContractGlobal" resultMap="contractResultMap">
- SELECT
- longitude,
- latitude
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- </select>
- <!--领导看板-统计国家-->
- <select id="getContractCountry" resultMap="contractResultMap">
- SELECT
- t1.customer_country_id,
- CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
- COUNT(t1.customer_country_id) as sumOrder
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- GROUP BY customer_country_id
- ORDER BY sumContractPrice DESC
- LIMIT 10
- </select>
- <!--领导看板-统计客户TOP10-->
- <select id="getContractCustomer" resultMap="contractResultMap">
- SELECT
- t1.customer_id,
- CONVERT(IFNULL(SUM( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) AS sumContractPrice
- FROM
- t_erp_contract t1
- <include refid="getBoardCondition" />
- GROUP BY
- customer_id
- ORDER BY sumContractPrice DESC
- LIMIT 10
- </select>
- <!--领导看板-统计业务员-->
- <select id="getContractUser" resultMap="contractResultMap">
- SELECT
- *
- FROM
- (SELECT
- t2.real_name AS create_user_name,
- CONVERT(IFNULL(SUM( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) AS sumContractPrice
- FROM
- blade_user t2
- LEFT JOIN (
- SELECT * FROM
- t_erp_contract t1
- <include refid="getBoardCondition"/> ) t1
- ON t2.id = t1.create_user
- WHERE
- t2.tenant_id = #{tenantId}
- AND t2.role_id regexp #{roleId}
- GROUP BY
- t2.id
- ) AS a
- ORDER BY
- a.sumContractPrice DESC
- </select>
- <!--领导看板-统计产品金额-->
- <select id="getContractProductPrice" resultMap="contractResultMap">
- SELECT
- t2.product_id,
- t2.product_name AS create_user_name,
- CONVERT (
- IFNULL( SUM( t2.sum_price * t1.tax_rate ), 0 ),
- DECIMAL ( 10, 2 )) AS sumContractPrice
- FROM
- t_erp_contract_product t2
- LEFT JOIN t_erp_contract t1 ON t2.contract_id = t1.id
- <include refid="getBoardCondition"/>
- GROUP BY
- t2.product_id
- ORDER BY
- sumContractPrice DESC
- LIMIT 10
- </select>
- <!--领导看板-统计产品数量-->
- <select id="getContractProductOrder" resultMap="contractResultMap">
- SELECT
- t2.product_id,
- t2.product_name AS create_user_name,
- IFNULL( SUM( t2.quantity ), 0 ) AS sumOrder
- FROM
- t_erp_contract_product t2
- LEFT JOIN t_erp_contract t1 on t2.contract_id=t1.id
- <include refid="getBoardCondition"/>
- GROUP BY
- t2.product_id
- ORDER BY
- sumOrder DESC
- LIMIT 30
- </select>
- <sql id="getBoardCondition">
- <where>
- t1.is_change in(0,2)
- AND t1.tenant_id = #{tenantId}
- AND t1.`status` >= 40
- <![CDATA[ AND t1.`status` < 999 ]]>
- AND t1.data_type = 0
- <if test="startTime neq null and startTime neq '' and
- endTime neq null and endTime neq ''">
- and t1.create_time between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
- </if>
- </where>
- </sql>
- <!--领导看板,订单分析-统计本周、本月、本年总销售额和订单数-->
- <select id="getSumBoardDayYMD" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
- count(1) as sumOrder,
- DATE_FORMAT(create_time,'%Y-%m-%d') as dayTime
- FROM
- t_erp_contract t1
- <include refid="getcondition"/>
- </select>
- <!--领导看板,订单分析-统计本周、本月、本年总销售额和订单数-->
- <select id="getSumBoardOrder" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
- count(1) as sumOrder
- FROM
- t_erp_contract t1
- <include refid="getSumCondition"/>
- </select>
- <!--领导看板,订单分析-订单跟进-->
- <select id="getSumBoardStatusDayYMD" resultMap="contractResultMap">
- select
- count(1) as sumOrder,
- t1.`status` as status
- from t_erp_contract t1
- <include refid="getBoardOrderCondition"/>
- GROUP BY t1.`status`
- </select>
- <sql id="getBoardOrderCondition">
- <where>
- t1.tenant_id = #{tenantId}
- <choose>
- <!--本周-->
- <when test="type neq null and type neq '' and type eq 1 ">
- AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
- </when>
- <!--本月-->
- <when test="type neq null and type neq '' and type eq 2 ">
- AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
- </when>
- <!--本年-->
- <when test="type neq null and type neq '' and type eq 3 ">
- AND YEAR(create_time)=YEAR(NOW())
- </when>
- <otherwise>
- <if test="contractStartStr neq null and contractStartStr neq '' and
- contractEndStr neq null and contractEndStr neq ''">
- and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
- </if>
- </otherwise>
- </choose>
- </where>
- </sql>
- <update id="transfer">
- UPDATE t_erp_contract
- <set>
- create_user = #{userId}
- </set>
- <where>
- tenant_id = #{tenantId}
- AND customer_id = #{customerId}
- </where>
- </update>
- <!--根据条件查询样品单和外销合同总条数-->
- <select id="getSumContractByYMD" resultMap="contractResultMap">
- select count(data_type) as sumOrder,data_type from t_erp_contract t1
- <include refid="getBoardCondition"/>
- <if test="createUser neq null and createUser neq ''">
- and t1.create_user = #{createUser}
- </if>
- GROUP BY data_type
- </select>
- <!--根据条件查询样品单和外销合同总条数-->
- <select id="getSumContractPriceByYMD" resultType="java.lang.Double">
- select SUM(contract_price*tax_rate) as sumContractPrice from t_erp_contract t1
- <include refid="getBoardCondition"/>
- <if test="createUser neq null and createUser neq ''">
- and t1.create_user = #{createUser}
- </if>
- GROUP BY create_user
- </select>
- <!--获取员工日报右侧合同与样品单列表-->
- <select id="getDailyContract" resultMap="contractResultMap">
- select
- *
- from t_erp_contract t1
- <include refid="getDailyCondition"/>
- </select>
- <select id="getDailyContractCount" resultType="java.lang.Integer">
- select
- count(1)
- from t_erp_contract t1
- <include refid="getDailyCondition"/>
- </select>
- <sql id="getDailyCondition">
- <where>
- t1.tenant_id = #{tenantId}
- AND `status` BETWEEN 20 and 998
- AND data_type = #{dataType}
- AND TO_DAYS(create_time) = TO_DAYS(NOW())
- AND create_user = #{createUser}
- </where>
- </sql>
- <select id="getUserDailyContractCount" resultType="java.lang.Integer">
- select
- count(1)
- from t_erp_contract t1
- <include refid="getUserDailyCondition"/>
- </select>
- <sql id="getUserDailyCondition">
- <where>
- t1.tenant_id = #{tenantId}
- AND `status` BETWEEN 20 and 998
- AND data_type = #{dataType}
- AND DATE_FORMAT(create_time,'%Y-%m-%d') = #{date}
- AND create_user = #{userId}
- </where>
- </sql>
- <!--总览-订单跟踪-统计总额-->
- <select id="getOrderTailAfterSum" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL( sum( contract_price * tax_rate ), 0 ),DECIMAL ( 10, 2 )) AS sumContractPrice,
- count( 1 ) AS sumOrder
- FROM
- t_erp_contract
- <include refid="pandect_condition"/>
- AND `status` BETWEEN 40 AND 110
- </select>
- <!--总览-订单跟踪-统计分类-->
- <select id="getOrderTailAfterSumStaus" resultMap="contractResultMap">
- SELECT
- CONVERT(IFNULL( sum( contract_price * tax_rate ), 0 ),DECIMAL ( 10, 2 )) AS sumContractPrice,
- count( 1 ) AS sumOrder,
- `status` AS STATUS
- FROM
- t_erp_contract
- <include refid="pandect_condition"/>
- GROUP BY `status`
- </select>
- <sql id="pandect_condition">
- <where>
- tenant_id = #{tenantId}
- <if test="userId neq null and userId neq ''">
- AND create_user = #{userId}
- </if>
- AND is_change IN ( 0, 2 )
- AND data_type = 0
- </where>
- </sql>
- <!-- 查询用户ID查询 -->
- <select id="getByUserIds" resultMap="contractResultMap">
- select
- id,
- (contract_price * IFNULL(tax_rate, 0)) contract_price,
- create_user,
- create_time
- from
- t_erp_contract
- <where>
- `status` >= 30
- <![CDATA[ and `status` < 999 ]]>
- and is_change in (0,2)
- and data_type = #{dataType}
- and create_user in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and DATE_FORMAT( create_time, '%Y' ) = #{year}
- </where>
- order by
- create_time asc
- </select>
- <!-- 查询用户ID查询 -->
- <select id="getByUserIdsJoin" resultMap="contractResultMap">
- select
- t2.id,
- t2.customer_id,
- t2.create_user,
- t1.create_time
- from
- t_erp_claim t1
- INNER JOIN t_erp_contract t2 on t1.contract_code = t2.`code`
- <where>
- t2.`status` >= 30
- <![CDATA[ and t2.`status` < 999 ]]>
- and t2.is_change in (0,2)
- and t2.data_type = #{dataType}
- and t2.create_user in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and DATE_FORMAT( t1.create_time, '%Y' ) = #{year}
- </where>
- order by
- t1.create_time asc
- </select>
- <!-- 根据子编号前缀代码统计 -->
- <select id="getCount" resultType="java.lang.Integer">
- select
- count(t1.`code`) count
- from
- t_erp_contract t1
- <where>
- t1.tenant_id = #{tenantId}
- and t1.`status` > 10
- and t1.data_type = #{dataType}
- <!-- 数据类型:0、外销合同 -->
- <if test="dataType eq 0">
- and t1.is_change in (0, 2)
- </if>
- <!-- 年份编号 -->
- <if test="prefixCode eq 1">
- and DATE_FORMAT( t1.create_time, '%y' ) = DATE_FORMAT( SYSDATE(), '%y')
- </if>
- <!-- 国家代码 -->
- <if test="prefixCode eq 3">
- and t1.customer_country_id = #{countryId}
- </if>
- <!-- 业务员代码 -->
- <if test="prefixCode eq 4">
- and t1.create_user = #{userId}
- </if>
- <!-- 客户代码 -->
- <if test="prefixCode eq 5">
- and t1.customer_id = #{customerId}
- </if>
- <!-- 产品代码 -->
- <if test="prefixCode eq 6">
- and EXISTS (
- select
- 1
- from
- t_erp_contract_product t2
- <where>
- t1.id = t2.contract_id
- and t2.product_id = #{productId}
- </where>
- GROUP BY
- t2.contract_id
- )
- </if>
- </where>
- </select>
- <!-- 查询销售信息 -->
- <select id="getOrderSale" resultType="com.alibaba.fastjson.JSONObject">
- SELECT
- tt.product_id productId,
- count( DISTINCT t.id ) orderCount,
- SUM( tt.quantity) quantity,
- SUM( tt.sum_price * tax_rate) sumPrice,
- MIN(tt.price * tax_rate) minPrice,
- MAX(tt.price * tax_rate) maxPrice
- FROM
- t_erp_contract t
- INNER JOIN t_erp_contract_product tt ON t.id = tt.contract_id
- <where>
- t.data_type = 0
- AND t.`status` > 20
- <![CDATA[ AND t.`status` < 999 ]]>
- AND t.is_change != 1
- AND t.tenant_id = #{tenantId}
- AND t.create_time >= #{startTime}
- <![CDATA[ AND t.create_time <= #{endTime} ]]>
- AND tt.product_id IN
- <foreach collection="productIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </where>
- GROUP BY
- tt.product_id
- </select>
- <!-- 查询销售合同ID -->
- <select id="getContractIds" resultMap="contractResultMap">
- SELECT
- t.id,
- tt.product_id
- FROM
- t_erp_contract t
- INNER JOIN t_erp_contract_product tt ON t.id = tt.contract_id
- <where>
- t.data_type = 0
- AND t.`status` > 20
- <![CDATA[ AND t.`status` < 999 ]]>
- AND t.is_change != 1
- AND t.tenant_id = #{tenantId}
- AND t.create_time >= #{startTime}
- <![CDATA[ AND t.create_time <= #{endTime} ]]>
- AND tt.product_id IN
- <foreach collection="productIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </where>
- </select>
- </mapper>
|