ContractMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fjhx.contract.mapper.ContractMapper">
  4. <resultMap id="contractResultMap" type="com.fjhx.contract.entity.Contract">
  5. <id column="id" property="id"/>
  6. <result column="code" property="code"/>
  7. <result column="invoice_code" property="invoiceCode"/>
  8. <result column="customer_id" property="customerId"/>
  9. <result column="customer_name" property="customerName"/>
  10. <result column="customer_lastname" property="customerLastname"/>
  11. <result column="customer_second_name" property="customerSecondName"/>
  12. <result column="customer_company_name" property="customerCompanyName"/>
  13. <result column="customer_country_id" property="customerCountryId"/>
  14. <result column="customer_country_name" property="customerCountryName"/>
  15. <result column="customer_state" property="customerState"/>
  16. <result column="customer_city_id" property="customerCityId"/>
  17. <result column="customer_city_name" property="customerCityName"/>
  18. <result column="customer_addr" property="customerAddr"/>
  19. <result column="customer_tel" property="customerTel"/>
  20. <result column="customer_zip_code" property="customerZipCode"/>
  21. <result column="customer_po" property="customerPo"/>
  22. <result column="customer_other_msg" property="customerOtherMsg"/>
  23. <result column="longitude" property="longitude"/>
  24. <result column="latitude" property="latitude"/>
  25. <result column="company_id" property="companyId"/>
  26. <result column="company_bank_id" property="companyBankId"/>
  27. <result column="company_bank_name" property="companyBankName"/>
  28. <result column="company_bank_card" property="companyBankCard"/>
  29. <result column="company_bank_swift_code" property="companyBankSwiftCode"/>
  30. <result column="company_bank_addr" property="companyBankAddr"/>
  31. <result column="company_bank_type" property="companyBankType"/>
  32. <result column="coll_name" property="collName"/>
  33. <result column="coll_address" property="collAddress"/>
  34. <result column="pay_way" property="payWay"/>
  35. <result column="pre_pay_ratio" property="prePayRatio"/>
  36. <result column="transfer_bank_name" property="transferBankName"/>
  37. <result column="transfer_bank_swift_code" property="transferBankSwiftCode"/>
  38. <result column="trade_mode_id" property="tradeModeId"/>
  39. <result column="payment_id" property="paymentId"/>
  40. <result column="payment_remark" property="paymentRemark"/>
  41. <result column="valid_time" property="validTime"/>
  42. <result column="delivery_day" property="deliveryDay"/>
  43. <result column="shipping_type" property="shippingType"/>
  44. <result column="express_id" property="expressId"/>
  45. <result column="wharf" property="wharf"/>
  46. <result column="currency_type" property="currencyType"/>
  47. <result column="contract_price" property="contractPrice"/>
  48. <result column="contract_price_en" property="contractPriceEn"/>
  49. <result column="status" property="status"/>
  50. <result column="approved_date" property="approvedDate"/>
  51. <result column="confirm_date" property="confirmDate"/>
  52. <result column="warranty_day" property="warrantyDay"/>
  53. <result column="join_type" property="joinType"/>
  54. <result column="join_id" property="joinId"/>
  55. <result column="process_instance_id" property="processInstanceId"/>
  56. <result column="process_instance_name" property="processInstanceName"/>
  57. <result column="process_instance_user_id" property="processInstanceUserId"/>
  58. <result column="process_instance_user_name" property="processInstanceUserName"/>
  59. <result column="source" property="source"/>
  60. <result column="remark" property="remark"/>
  61. <result column="is_change" property="isChange"/>
  62. <result column="change_cost" property="changeCost"/>
  63. <result column="change_cost2" property="changeCost2"/>
  64. <result column="change_cost3" property="changeCost3"/>
  65. <result column="change_remark" property="changeRemark"/>
  66. <result column="pre_contract_id" property="preContractId"/>
  67. <result column="version" property="version"/>
  68. <result column="data_type" property="dataType"/>
  69. <result column="action_type" property="actionType"/>
  70. <result column="contract_sample_confirm" property="contractSampleConfirm"/>
  71. <result column="tax_rate" property="taxRate"/>
  72. <result column="is_complete" property="isComplete"/>
  73. <result column="create_user" property="createUser"/>
  74. <result column="create_time" property="createTime"/>
  75. <result column="update_user" property="updateUser"/>
  76. <result column="update_time" property="updateTime"/>
  77. <!-- 扩展字段 -->
  78. <result column="create_user_name" property="createUserName"/>
  79. <result column="create_date" property="createDate"/>
  80. <result column="order_count" property="orderCount"/>
  81. <result column="sumContractPrice" property="sumContractPrice"/>
  82. <result column="sumOrder" property="sumOrder"/>
  83. <result column="dayTime" property="dayTime"/>
  84. <result column="product_id" property="productId"/>
  85. </resultMap>
  86. <sql id="sqlField">
  87. SELECT * FROM t_erp_contract
  88. </sql>
  89. <select id="getList" resultMap="contractResultMap">
  90. SELECT
  91. t1.id,
  92. t1.type,
  93. t1.`code`,
  94. t1.`status`,
  95. t1.version,
  96. t1.source,
  97. t1.create_time,
  98. t1.customer_id,
  99. t1.customer_company_name,
  100. t1.customer_name,
  101. t1.contract_price,
  102. t1.currency_type,
  103. t1.is_change,
  104. t1.contract_sample_confirm,
  105. t1.process_instance_id,
  106. t1.is_complete,
  107. t1.company_id,
  108. t2.real_name AS create_user_name
  109. FROM
  110. t_erp_contract t1
  111. LEFT JOIN blade_user t2 ON t1.create_user = t2.id
  112. <include refid="getListCondition" />
  113. <!-- 列表类型,1:外销合同管理列表、2:邮件-右侧外销合同列表、3:成单样品合同列表、4:到账认领选择合同、5:邮件-右侧成单样品合同列表 -->
  114. <choose>
  115. <when test="listType neq null and (listType eq 1 or listType eq 3 or listType eq 4)">
  116. ORDER BY
  117. t1.code DESC
  118. </when>
  119. <otherwise>
  120. ORDER BY
  121. t1.create_time DESC
  122. </otherwise>
  123. </choose>
  124. <include refid="Sql.sql_limit" />
  125. </select>
  126. <select id="getListCount" resultType="java.lang.Integer">
  127. SELECT
  128. COUNT(*) AS c
  129. FROM
  130. t_erp_contract t1
  131. LEFT JOIN blade_user t2 ON t1.create_user = t2.id
  132. <include refid="getListCondition" />
  133. </select>
  134. <sql id="getListCondition">
  135. <where>
  136. t1.tenant_id = #{tenantId}
  137. <!-- 列表类型,1:外销合同管理列表、2:邮件-右侧外销合同列表、3:成单样品合同列表、4:到账认领选择合同、5:邮件-右侧成单样品合同列表 -->
  138. <!-- data_type数据类型,0:外销合同、1:成单样品 -->
  139. <choose>
  140. <when test="listType neq null and (listType eq 1 or listType eq 2)">
  141. AND t1.data_type = 0
  142. </when>
  143. <when test="listType neq null and (listType eq 3 or listType eq 5)">
  144. AND t1.data_type = 1
  145. </when>
  146. <when test="listType neq null and listType eq 4">
  147. <!-- 未确认 and 未结清 -->
  148. <![CDATA[ AND t1.`status` >= 30 AND t1.`status` <= 110 ]]>
  149. <!-- 是否处于变更中,0、不存在变更;1:本身为变更数据(表示从元数据被发起变更后的新数据);2:存在变更数据(表示元数据被发起变更) -->
  150. AND t1.is_change IN(0, 2)
  151. </when>
  152. </choose>
  153. <choose>
  154. <when test="listType neq null and listType eq 2">
  155. AND t1.status != 999
  156. <!-- 是否处于变更中,0、不存在变更;1:本身为变更数据(表示从元数据被发起变更后的新数据);2:存在变更数据(表示元数据被发起变更) -->
  157. AND t1.is_change IN(0, 2)
  158. </when>
  159. <otherwise>
  160. AND t1.status != 999
  161. </otherwise>
  162. </choose>
  163. <if test="userId neq null and userId neq ''">
  164. AND t1.create_user = #{userId}
  165. </if>
  166. <if test="status neq null and status neq ''">
  167. AND t1.status = #{status}
  168. </if>
  169. <!-- 钉钉使用 -->
  170. <if test="statusRange neq null and statusRange neq ''">
  171. AND t1.status >= #{statusRange}
  172. </if>
  173. <if test="source neq null and source neq ''">
  174. AND t1.source = #{source}
  175. </if>
  176. <if test="code neq null and code neq ''">
  177. AND (INSTR(t1.`code`, #{code}) > 0)
  178. </if>
  179. <if test="customerCompanyName neq null and customerCompanyName neq ''">
  180. AND (INSTR(t1.customer_company_name, #{customerCompanyName}) > 0)
  181. </if>
  182. <if test="customerName neq null and customerName neq ''">
  183. AND (INSTR(t1.customer_name, #{customerName}) > 0)
  184. </if>
  185. <if test="createUserName neq null and createUserName neq ''">
  186. AND (
  187. INSTR(t2.`name`, #{createUserName}) > 0
  188. OR
  189. INSTR(t2.real_name, #{createUserName}) > 0
  190. )
  191. </if>
  192. <if test="keyWord neq null and keyWord neq ''">
  193. AND (
  194. INSTR(t1.`code`, #{keyWord}) > 0
  195. OR
  196. INSTR(t1.customer_company_name, #{keyWord}) > 0
  197. )
  198. </if>
  199. <if test="customerIds neq null and customerIds.size() > 0">
  200. <foreach collection="customerIds" item="customerId" open="AND t1.customer_id IN (" separator=","
  201. close=")">
  202. #{customerId}
  203. </foreach>
  204. </if>
  205. <if test="customerId neq null and customerId neq ''">
  206. AND t1.customer_id = #{customerId}
  207. </if>
  208. <!-- 关联类型(制作合同时使用),1:关联成单样品 -->
  209. <if test="joinType neq null and joinType eq 1">
  210. <!-- 排除已被关联的数据 -->
  211. AND NOT EXISTS (
  212. SELECT
  213. 1
  214. FROM
  215. t_erp_contract t3
  216. <where>
  217. t3.tenant_id = #{tenantId}
  218. AND t3.join_id = t1.id
  219. </where>
  220. )
  221. </if>
  222. <!-- 日历统计使用 -->
  223. <if test="beginDate neq null and beginDate neq '' and endDate neq null and endDate neq ''">
  224. <if test="listType neq null and listType eq 1">
  225. AND t1.`status` >= 30
  226. <![CDATA[ AND t1.`status` < 110 ]]>
  227. </if>
  228. AND EXISTS (
  229. SELECT
  230. 1
  231. FROM
  232. t_erp_shipment_detailed t3
  233. WHERE
  234. t1.id = t3.business_id
  235. AND DATE_FORMAT( t3.shipment_time, '%Y-%m-%d' ) >= #{beginDate}
  236. <![CDATA[ AND DATE_FORMAT( t3.shipment_time, '%Y-%m-%d' ) <= #{endDate} ]]>
  237. )
  238. </if>
  239. <!-- 数据看板 二级清单 -->
  240. <if test="ids neq null and ids.size > 0">
  241. AND t1.id IN
  242. <foreach collection="ids" item="item" open="(" separator="," close=")">
  243. #{item}
  244. </foreach>
  245. </if>
  246. <if test="isComplete neq null and isComplete neq ''">
  247. AND t1.is_complete = #{isComplete}
  248. </if>
  249. <if test="type neq null and type neq ''">
  250. AND t1.type=#{type}
  251. </if>
  252. </where>
  253. </sql>
  254. <update id="updateStatusById">
  255. UPDATE t_erp_contract
  256. <set>
  257. <if test="status neq null">status = #{status},</if>
  258. <if test="updateUser neq null">update_user = #{updateUser},</if>
  259. update_time = NOW()
  260. </set>
  261. <where>
  262. id IN
  263. <foreach collection="ids" item="id" open="(" separator="," close=")">
  264. #{id}
  265. </foreach>
  266. <!-- 合同状态如果走到后面不允许回滚到前面的状态,com.ruoyi.common.enums.ContractStatusEnum -->
  267. <![CDATA[
  268. AND `status` < #{status}
  269. ]]>
  270. </where>
  271. </update>
  272. <select id="getNextVersionByCode" resultType="java.lang.Integer">
  273. SELECT
  274. MAX(t1.version) AS version
  275. FROM
  276. t_erp_contract t1
  277. <where>
  278. <!-- 有效的合同 -->
  279. t1.`status` != 999
  280. AND t1.`code` = #{code}
  281. </where>
  282. </select>
  283. <!-- 客户画像:销售分析列表 -->
  284. <select id="getSalesAnalysisList" resultMap="contractResultMap">
  285. SELECT
  286. <!-- 时间条件类型:非年度查询 -->
  287. <if test="timeConditionType eq 0">
  288. DATE_FORMAT( create_time, '%Y-%m-%d' ) create_date,
  289. </if>
  290. <!-- 时间条件类型:年度查询 -->
  291. <if test="timeConditionType eq 1">
  292. DATE_FORMAT( create_time, '%Y-%m' ) create_date,
  293. </if>
  294. count( id ) order_count,
  295. SUM( contract_price ) contract_price
  296. FROM
  297. t_erp_contract
  298. <!-- 客户画像:销售分析列表条件 -->
  299. <include refid="getSalesAnalysisListCondition" />
  300. ORDER BY
  301. create_time ASC
  302. <include refid="Sql.sql_limit" />
  303. </select>
  304. <!-- 客户画像:销售分析列表总数 -->
  305. <select id="getSalesAnalysisListCount" resultType="java.lang.Integer">
  306. SELECT
  307. count(*) count
  308. FROM
  309. (
  310. SELECT
  311. DATE_FORMAT( create_time, '%Y-%m-%d' ) create_date
  312. FROM
  313. t_erp_contract
  314. <!-- 客户画像:销售分析列表条件 -->
  315. <include refid="getSalesAnalysisListCondition" />
  316. ) t
  317. </select>
  318. <!-- 客户画像:销售分析列表条件 -->
  319. <sql id="getSalesAnalysisListCondition">
  320. <where>
  321. customer_id = #{customerId}
  322. <!-- 时间条件类型:非年度查询 -->
  323. <if test="timeConditionType eq 0">
  324. <if test="startDate neq null and startDate neq ''">
  325. AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{startDate}
  326. </if>
  327. <if test="endDate neq null and endDate neq ''">
  328. <![CDATA[ AND DATE_FORMAT(create_time, '%Y-%m-%d') <= #{endDate} ]]>
  329. </if>
  330. </if>
  331. <!-- 时间条件类型:年度查询 -->
  332. <if test="timeConditionType eq 1">
  333. <if test="startDate neq null and startDate neq ''">
  334. AND DATE_FORMAT(create_time, '%Y-%m') >= #{startDate}
  335. </if>
  336. <if test="endDate neq null and endDate neq ''">
  337. <![CDATA[ AND DATE_FORMAT(create_time, '%Y-%m') <= #{endDate} ]]>
  338. </if>
  339. </if>
  340. </where>
  341. GROUP BY
  342. create_date
  343. </sql>
  344. <select id="getByCustomerId" resultMap="contractResultMap">
  345. SELECT
  346. t1.id,
  347. t1.`code`
  348. FROM
  349. t_erp_contract t1
  350. <where>
  351. t1.tenant_id = #{tenantId}
  352. AND t1.customer_id = #{customerId}
  353. </where>
  354. </select>
  355. <!--客户画像,销售统计柱状图-->
  356. <select id="getByCustomerIdAndDWM" resultMap="contractResultMap">
  357. SELECT
  358. t1.contract_price ,
  359. t1.create_time
  360. FROM
  361. t_erp_contract t1
  362. <include refid="getcondition"/>
  363. </select>
  364. <!--客户画像,售后合同下拉框-->
  365. <select id="getContractSelect" resultMap="contractResultMap">
  366. SELECT
  367. id,
  368. `code`
  369. FROM
  370. t_erp_contract
  371. WHERE
  372. customer_id = #{customerId}
  373. AND tenant_id = #{tenantId}
  374. AND `status` BETWEEN 20 AND 998
  375. </select>
  376. <!--客户画像,统计总销售额和订单数-->
  377. <select id="getByCustomerIdSumDWM" resultMap="contractResultMap">
  378. SELECT
  379. CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
  380. count(1) as sumOrder
  381. FROM
  382. t_erp_contract t1
  383. <include refid="getcondition"/>
  384. </select>
  385. <!--客户画像,统计本周、本月、本年总销售额和订单数-->
  386. <select id="getByCustomerIdSumDayDWM" resultMap="contractResultMap">
  387. SELECT
  388. CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
  389. count(1) as sumOrder,
  390. DATE_FORMAT(create_time,'%Y-%m-%d') as dayTime
  391. FROM
  392. t_erp_contract t1
  393. <include refid="getcondition"/>
  394. </select>
  395. <sql id="getcondition">
  396. <where>
  397. t1.tenant_id = #{tenantId}
  398. <if test="customerId neq null and customerId neq ''">
  399. AND t1.customer_id = #{customerId}
  400. </if>
  401. <choose>
  402. <!--本周-->
  403. <when test="type neq null and type neq '' and type eq 1 ">
  404. AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
  405. GROUP BY DATE_FORMAT(create_time,'%m-%d')
  406. </when>
  407. <!--本月-->
  408. <when test="type neq null and type neq '' and type eq 2 ">
  409. AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
  410. GROUP BY DATE_FORMAT(create_time,'%m-%d')
  411. </when>
  412. <!--本年-->
  413. <when test="type neq null and type neq '' and type eq 3 ">
  414. AND YEAR(create_time)=YEAR(NOW())
  415. GROUP BY DATE_FORMAT(create_time,'%Y-%m')
  416. </when>
  417. <otherwise>
  418. <if test="contractStartStr neq null and contractStartStr neq '' and
  419. contractEndStr neq null and contractEndStr neq ''">
  420. and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
  421. GROUP BY DATE_FORMAT(create_time,'%m-%d')
  422. </if>
  423. </otherwise>
  424. </choose>
  425. </where>
  426. </sql>
  427. <sql id="getSumCondition">
  428. <where>
  429. t1.tenant_id = #{tenantId}
  430. <choose>
  431. <!--本周-->
  432. <when test="type neq null and type neq '' and type eq 1 ">
  433. AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
  434. </when>
  435. <!--本月-->
  436. <when test="type neq null and type neq '' and type eq 2 ">
  437. AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
  438. </when>
  439. <!--本年-->
  440. <when test="type neq null and type neq '' and type eq 3 ">
  441. AND YEAR(create_time)=YEAR(NOW())
  442. </when>
  443. <otherwise>
  444. <if test="contractStartStr neq null and contractStartStr neq '' and
  445. contractEndStr neq null and contractEndStr neq ''">
  446. and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
  447. </if>
  448. </otherwise>
  449. </choose>
  450. </where>
  451. </sql>
  452. <!--外销合同-样品单查询-->
  453. <select id="getHuaXList" resultMap="contractResultMap">
  454. SELECT
  455. t1.id,
  456. t1.`code`,
  457. t1.`status`,
  458. t1.version,
  459. t1.source,
  460. t1.create_time,
  461. t1.customer_company_name,
  462. t1.customer_name,
  463. t1.contract_price,
  464. t1.currency_type,
  465. t1.is_change,
  466. t1.contract_sample_confirm,
  467. t1.process_instance_id,
  468. t2.real_name AS create_user_name
  469. FROM
  470. t_erp_contract t1
  471. LEFT JOIN blade_user t2 ON t1.create_user = t2.id
  472. <include refid="getListHuaXCondition" />
  473. <!-- 列表类型-1:外销合同管理列表 2:成单样品合同列表-->
  474. ORDER BY
  475. t1.code DESC
  476. <include refid="Sql.sql_limit" />
  477. </select>
  478. <!--外销合同-样品单条数查询-->
  479. <select id="getHuaXListCount" resultType="java.lang.Integer">
  480. SELECT
  481. COUNT(*) AS c
  482. FROM
  483. t_erp_contract t1
  484. LEFT JOIN blade_user t2 ON t1.create_user = t2.id
  485. <include refid="getListHuaXCondition" />
  486. </select>
  487. <sql id="getListHuaXCondition">
  488. <where>
  489. t1.tenant_id = #{tenantId}
  490. <if test="customerId neq null and customerId neq ''">
  491. AND t1.`customer_id` = #{customerId}
  492. </if>
  493. <!-- data_type数据类型,0:外销合同、1:成单样品 -->
  494. <if test="listType neq null and (listType eq 1)">
  495. AND t1.data_type = 0
  496. </if>
  497. <if test="listType neq null and (listType eq 3)">
  498. AND t1.data_type = 1
  499. </if>
  500. <if test="status neq null and status neq ''">
  501. AND t1.status = #{status}
  502. </if>
  503. <if test="createUserName neq null and createUserName neq ''">
  504. AND (
  505. INSTR(t2.`name`, #{createUserName}) > 0
  506. OR
  507. INSTR(t2.real_name, #{createUserName}) > 0
  508. )
  509. </if>
  510. <if test="contractStartStr neq null and contractStartStr neq '' and
  511. contractEndStr neq null and contractEndStr neq ''">
  512. and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
  513. </if>
  514. </where>
  515. </sql>
  516. <!--领导看板-统计总销售额-->
  517. <select id="getContractSumPrice" resultType="java.lang.String">
  518. SELECT
  519. CONVERT (
  520. IFNULL( SUM( t1.contract_price * t1.tax_rate ), 0 ),
  521. DECIMAL ( 10, 2 )) AS sumContractPrice
  522. FROM
  523. t_erp_contract t1
  524. <include refid="getBoardCondition" />
  525. </select>
  526. <!--领导看板-统计下单数-->
  527. <select id="getContractSumOrder" resultType="java.lang.String">
  528. SELECT
  529. COUNT(1)
  530. FROM
  531. t_erp_contract t1
  532. <include refid="getBoardCondition" />
  533. </select>
  534. <!--领导看板-下单客户数-->
  535. <select id="getContractSumCustomer" resultType="java.lang.Integer">
  536. SELECT
  537. COUNT(1)
  538. FROM(
  539. SELECT
  540. COUNT(1)
  541. FROM
  542. t_erp_contract t1
  543. <include refid="getBoardCondition" />
  544. GROUP BY
  545. customer_id
  546. ) AS a
  547. </select>
  548. <!--领导看板-统计全球-获取经纬度坐标-->
  549. <select id="getContractGlobal" resultMap="contractResultMap">
  550. SELECT
  551. longitude,
  552. latitude
  553. FROM
  554. t_erp_contract t1
  555. <include refid="getBoardCondition" />
  556. </select>
  557. <!--领导看板-统计国家-->
  558. <select id="getContractCountry" resultMap="contractResultMap">
  559. SELECT
  560. t1.customer_country_id,
  561. CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
  562. COUNT(t1.customer_country_id) as sumOrder
  563. FROM
  564. t_erp_contract t1
  565. <include refid="getBoardCondition" />
  566. GROUP BY customer_country_id
  567. ORDER BY sumContractPrice DESC
  568. LIMIT 10
  569. </select>
  570. <!--领导看板-统计客户TOP10-->
  571. <select id="getContractCustomer" resultMap="contractResultMap">
  572. SELECT
  573. t1.customer_id,
  574. CONVERT(IFNULL(SUM( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) AS sumContractPrice
  575. FROM
  576. t_erp_contract t1
  577. <include refid="getBoardCondition" />
  578. GROUP BY
  579. customer_id
  580. ORDER BY sumContractPrice DESC
  581. LIMIT 10
  582. </select>
  583. <!--领导看板-统计业务员-->
  584. <select id="getContractUser" resultMap="contractResultMap">
  585. SELECT
  586. *
  587. FROM
  588. (SELECT
  589. t2.real_name AS create_user_name,
  590. CONVERT(IFNULL(SUM( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) AS sumContractPrice
  591. FROM
  592. blade_user t2
  593. LEFT JOIN (
  594. SELECT * FROM
  595. t_erp_contract t1
  596. <include refid="getBoardCondition"/> ) t1
  597. ON t2.id = t1.create_user
  598. WHERE
  599. t2.tenant_id = #{tenantId}
  600. AND t2.role_id regexp #{roleId}
  601. GROUP BY
  602. t2.id
  603. ) AS a
  604. ORDER BY
  605. a.sumContractPrice DESC
  606. </select>
  607. <!--领导看板-统计产品金额-->
  608. <select id="getContractProductPrice" resultMap="contractResultMap">
  609. SELECT
  610. t2.product_id,
  611. t2.product_name AS create_user_name,
  612. CONVERT (
  613. IFNULL( SUM( t2.sum_price * t1.tax_rate ), 0 ),
  614. DECIMAL ( 10, 2 )) AS sumContractPrice
  615. FROM
  616. t_erp_contract_product t2
  617. LEFT JOIN t_erp_contract t1 ON t2.contract_id = t1.id
  618. <include refid="getBoardCondition"/>
  619. GROUP BY
  620. t2.product_id
  621. ORDER BY
  622. sumContractPrice DESC
  623. LIMIT 10
  624. </select>
  625. <!--领导看板-统计产品数量-->
  626. <select id="getContractProductOrder" resultMap="contractResultMap">
  627. SELECT
  628. t2.product_id,
  629. t2.product_name AS create_user_name,
  630. IFNULL( SUM( t2.quantity ), 0 ) AS sumOrder
  631. FROM
  632. t_erp_contract_product t2
  633. LEFT JOIN t_erp_contract t1 on t2.contract_id=t1.id
  634. <include refid="getBoardCondition"/>
  635. GROUP BY
  636. t2.product_id
  637. ORDER BY
  638. sumOrder DESC
  639. LIMIT 30
  640. </select>
  641. <sql id="getBoardCondition">
  642. <where>
  643. t1.is_change in(0,2)
  644. AND t1.tenant_id = #{tenantId}
  645. AND t1.`status` >= 40
  646. <![CDATA[ AND t1.`status` < 999 ]]>
  647. AND t1.data_type = 0
  648. <if test="startTime neq null and startTime neq '' and
  649. endTime neq null and endTime neq ''">
  650. and t1.create_time between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
  651. </if>
  652. </where>
  653. </sql>
  654. <!--领导看板,订单分析-统计本周、本月、本年总销售额和订单数-->
  655. <select id="getSumBoardDayYMD" resultMap="contractResultMap">
  656. SELECT
  657. CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
  658. count(1) as sumOrder,
  659. DATE_FORMAT(create_time,'%Y-%m-%d') as dayTime
  660. FROM
  661. t_erp_contract t1
  662. <include refid="getcondition"/>
  663. </select>
  664. <!--领导看板,订单分析-统计本周、本月、本年总销售额和订单数-->
  665. <select id="getSumBoardOrder" resultMap="contractResultMap">
  666. SELECT
  667. CONVERT(IFNULL(sum( t1.contract_price*t1.tax_rate ),0),decimal(10,2)) as sumContractPrice,
  668. count(1) as sumOrder
  669. FROM
  670. t_erp_contract t1
  671. <include refid="getSumCondition"/>
  672. </select>
  673. <!--领导看板,订单分析-订单跟进-->
  674. <select id="getSumBoardStatusDayYMD" resultMap="contractResultMap">
  675. select
  676. count(1) as sumOrder,
  677. t1.`status` as status
  678. from t_erp_contract t1
  679. <include refid="getBoardOrderCondition"/>
  680. GROUP BY t1.`status`
  681. </select>
  682. <sql id="getBoardOrderCondition">
  683. <where>
  684. t1.tenant_id = #{tenantId}
  685. <choose>
  686. <!--本周-->
  687. <when test="type neq null and type neq '' and type eq 1 ">
  688. AND YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())
  689. </when>
  690. <!--本月-->
  691. <when test="type neq null and type neq '' and type eq 2 ">
  692. AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' )
  693. </when>
  694. <!--本年-->
  695. <when test="type neq null and type neq '' and type eq 3 ">
  696. AND YEAR(create_time)=YEAR(NOW())
  697. </when>
  698. <otherwise>
  699. <if test="contractStartStr neq null and contractStartStr neq '' and
  700. contractEndStr neq null and contractEndStr neq ''">
  701. and t1.create_time between #{contractStartStr,jdbcType=VARCHAR} and #{contractEndStr,jdbcType=VARCHAR}
  702. </if>
  703. </otherwise>
  704. </choose>
  705. </where>
  706. </sql>
  707. <update id="transfer">
  708. UPDATE t_erp_contract
  709. <set>
  710. create_user = #{userId}
  711. </set>
  712. <where>
  713. tenant_id = #{tenantId}
  714. AND customer_id = #{customerId}
  715. </where>
  716. </update>
  717. <!--根据条件查询样品单和外销合同总条数-->
  718. <select id="getSumContractByYMD" resultMap="contractResultMap">
  719. select count(data_type) as sumOrder,data_type from t_erp_contract t1
  720. <include refid="getBoardCondition"/>
  721. <if test="createUser neq null and createUser neq ''">
  722. and t1.create_user = #{createUser}
  723. </if>
  724. GROUP BY data_type
  725. </select>
  726. <!--根据条件查询样品单和外销合同总条数-->
  727. <select id="getSumContractPriceByYMD" resultType="java.lang.Double">
  728. select SUM(contract_price*tax_rate) as sumContractPrice from t_erp_contract t1
  729. <include refid="getBoardCondition"/>
  730. <if test="createUser neq null and createUser neq ''">
  731. and t1.create_user = #{createUser}
  732. </if>
  733. GROUP BY create_user
  734. </select>
  735. <!--获取员工日报右侧合同与样品单列表-->
  736. <select id="getDailyContract" resultMap="contractResultMap">
  737. select
  738. *
  739. from t_erp_contract t1
  740. <include refid="getDailyCondition"/>
  741. </select>
  742. <select id="getDailyContractCount" resultType="java.lang.Integer">
  743. select
  744. count(1)
  745. from t_erp_contract t1
  746. <include refid="getDailyCondition"/>
  747. </select>
  748. <sql id="getDailyCondition">
  749. <where>
  750. t1.tenant_id = #{tenantId}
  751. AND `status` BETWEEN 20 and 998
  752. AND data_type = #{dataType}
  753. AND TO_DAYS(create_time) = TO_DAYS(NOW())
  754. AND create_user = #{createUser}
  755. </where>
  756. </sql>
  757. <select id="getUserDailyContractCount" resultType="java.lang.Integer">
  758. select
  759. count(1)
  760. from t_erp_contract t1
  761. <include refid="getUserDailyCondition"/>
  762. </select>
  763. <sql id="getUserDailyCondition">
  764. <where>
  765. t1.tenant_id = #{tenantId}
  766. AND `status` BETWEEN 20 and 998
  767. AND data_type = #{dataType}
  768. AND DATE_FORMAT(create_time,'%Y-%m-%d') = #{date}
  769. AND create_user = #{userId}
  770. </where>
  771. </sql>
  772. <!--总览-订单跟踪-统计总额-->
  773. <select id="getOrderTailAfterSum" resultMap="contractResultMap">
  774. SELECT
  775. CONVERT(IFNULL( sum( contract_price * tax_rate ), 0 ),DECIMAL ( 10, 2 )) AS sumContractPrice,
  776. count( 1 ) AS sumOrder
  777. FROM
  778. t_erp_contract
  779. <include refid="pandect_condition"/>
  780. AND `status` BETWEEN 40 AND 110
  781. </select>
  782. <!--总览-订单跟踪-统计分类-->
  783. <select id="getOrderTailAfterSumStaus" resultMap="contractResultMap">
  784. SELECT
  785. CONVERT(IFNULL( sum( contract_price * tax_rate ), 0 ),DECIMAL ( 10, 2 )) AS sumContractPrice,
  786. count( 1 ) AS sumOrder,
  787. `status` AS STATUS
  788. FROM
  789. t_erp_contract
  790. <include refid="pandect_condition"/>
  791. GROUP BY `status`
  792. </select>
  793. <sql id="pandect_condition">
  794. <where>
  795. tenant_id = #{tenantId}
  796. <if test="userId neq null and userId neq ''">
  797. AND create_user = #{userId}
  798. </if>
  799. AND is_change IN ( 0, 2 )
  800. AND data_type = 0
  801. </where>
  802. </sql>
  803. <!-- 查询用户ID查询 -->
  804. <select id="getByUserIds" resultMap="contractResultMap">
  805. select
  806. id,
  807. (contract_price * IFNULL(tax_rate, 0)) contract_price,
  808. create_user,
  809. create_time
  810. from
  811. t_erp_contract
  812. <where>
  813. `status` >= 30
  814. <![CDATA[ and `status` < 999 ]]>
  815. and is_change in (0,2)
  816. and data_type = #{dataType}
  817. and create_user in
  818. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  819. #{item}
  820. </foreach>
  821. and DATE_FORMAT( create_time, '%Y' ) = #{year}
  822. </where>
  823. order by
  824. create_time asc
  825. </select>
  826. <!-- 查询用户ID查询 -->
  827. <select id="getByUserIdsJoin" resultMap="contractResultMap">
  828. select
  829. t2.id,
  830. t2.customer_id,
  831. t2.create_user,
  832. t1.create_time
  833. from
  834. t_erp_claim t1
  835. INNER JOIN t_erp_contract t2 on t1.contract_code = t2.`code`
  836. <where>
  837. t2.`status` >= 30
  838. <![CDATA[ and t2.`status` < 999 ]]>
  839. and t2.is_change in (0,2)
  840. and t2.data_type = #{dataType}
  841. and t2.create_user in
  842. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  843. #{item}
  844. </foreach>
  845. and DATE_FORMAT( t1.create_time, '%Y' ) = #{year}
  846. </where>
  847. order by
  848. t1.create_time asc
  849. </select>
  850. <!-- 根据子编号前缀代码统计 -->
  851. <select id="getCount" resultType="java.lang.Integer">
  852. select
  853. count(t1.`code`) count
  854. from
  855. t_erp_contract t1
  856. <where>
  857. t1.tenant_id = #{tenantId}
  858. and t1.`status` > 10
  859. and t1.data_type = #{dataType}
  860. <!-- 数据类型:0、外销合同 -->
  861. <if test="dataType eq 0">
  862. and t1.is_change in (0, 2)
  863. </if>
  864. <!-- 年份编号 -->
  865. <if test="prefixCode eq 1">
  866. and DATE_FORMAT( t1.create_time, '%y' ) = DATE_FORMAT( SYSDATE(), '%y')
  867. </if>
  868. <!-- 国家代码 -->
  869. <if test="prefixCode eq 3">
  870. and t1.customer_country_id = #{countryId}
  871. </if>
  872. <!-- 业务员代码 -->
  873. <if test="prefixCode eq 4">
  874. and t1.create_user = #{userId}
  875. </if>
  876. <!-- 客户代码 -->
  877. <if test="prefixCode eq 5">
  878. and t1.customer_id = #{customerId}
  879. </if>
  880. <!-- 产品代码 -->
  881. <if test="prefixCode eq 6">
  882. and EXISTS (
  883. select
  884. 1
  885. from
  886. t_erp_contract_product t2
  887. <where>
  888. t1.id = t2.contract_id
  889. and t2.product_id = #{productId}
  890. </where>
  891. GROUP BY
  892. t2.contract_id
  893. )
  894. </if>
  895. </where>
  896. </select>
  897. <!-- 查询销售信息 -->
  898. <select id="getOrderSale" resultType="com.alibaba.fastjson.JSONObject">
  899. SELECT
  900. tt.product_id productId,
  901. count( DISTINCT t.id ) orderCount,
  902. SUM( tt.quantity) quantity,
  903. SUM( tt.sum_price * tax_rate) sumPrice,
  904. MIN(tt.price * tax_rate) minPrice,
  905. MAX(tt.price * tax_rate) maxPrice
  906. FROM
  907. t_erp_contract t
  908. INNER JOIN t_erp_contract_product tt ON t.id = tt.contract_id
  909. <where>
  910. t.data_type = 0
  911. AND t.`status` > 20
  912. <![CDATA[ AND t.`status` < 999 ]]>
  913. AND t.is_change != 1
  914. AND t.tenant_id = #{tenantId}
  915. AND t.create_time >= #{startTime}
  916. <![CDATA[ AND t.create_time <= #{endTime} ]]>
  917. AND tt.product_id IN
  918. <foreach collection="productIds" item="item" open="(" separator="," close=")">
  919. #{item}
  920. </foreach>
  921. </where>
  922. GROUP BY
  923. tt.product_id
  924. </select>
  925. <!-- 查询销售合同ID -->
  926. <select id="getContractIds" resultMap="contractResultMap">
  927. SELECT
  928. t.id,
  929. tt.product_id
  930. FROM
  931. t_erp_contract t
  932. INNER JOIN t_erp_contract_product tt ON t.id = tt.contract_id
  933. <where>
  934. t.data_type = 0
  935. AND t.`status` > 20
  936. <![CDATA[ AND t.`status` < 999 ]]>
  937. AND t.is_change != 1
  938. AND t.tenant_id = #{tenantId}
  939. AND t.create_time >= #{startTime}
  940. <![CDATA[ AND t.create_time <= #{endTime} ]]>
  941. AND tt.product_id IN
  942. <foreach collection="productIds" item="item" open="(" separator="," close=")">
  943. #{item}
  944. </foreach>
  945. </where>
  946. </select>
  947. </mapper>