OrderMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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.poteviohealth.cgp.statistics.mapper.OrderMapper">
  4. <select id="integralTransList" resultType="com.poteviohealth.cgp.statistics.model.outdto.IntegralTrans">
  5. SELECT
  6. IFNULL(
  7. c.now_city_id,(
  8. SELECT
  9. p.address_city_id
  10. FROM
  11. ${dbName}_common.f_operator p
  12. WHERE
  13. p.id = c.operator_id
  14. )) AS cityId,
  15. c.now_country_id AS countryId,
  16. c.now_street_id AS streetId,
  17. od.product_category_id AS productCategoryId,
  18. g.parent_id AS parentId,
  19. g.full_name AS fullName,
  20. t.trans_type AS transType,
  21. t.amount AS amount,
  22. t.build_time AS buildTime
  23. FROM
  24. ${dbName}_finance.c_card_acc_trans t
  25. LEFT JOIN ${dbName}_finance.c_card_acc_detail d ON t.detail_id = d.id
  26. LEFT JOIN ${dbName}_order.o_order_detail_${operatorId} od ON od.order_detail_id = t.trans_id
  27. LEFT JOIN ${dbName}_customer.c_customer_subsidy_${operatorId} c ON c.subsidy_customer_id = d.subsidy_customer_id
  28. LEFT JOIN ${dbName}_common.f_category g ON g.id = od.product_category_id
  29. WHERE
  30. d.yn = 0
  31. AND t.yn = 0
  32. AND d.ENABLE = 1
  33. AND d.type = 2
  34. AND t.trans_type IN (0,1)
  35. and ${ew.sqlSegment}
  36. </select>
  37. <select id="integralCustomerList" resultType="com.poteviohealth.cgp.statistics.model.outdto.IntegralTrans">
  38. SELECT
  39. c.age AS age,
  40. c.sex AS sex,
  41. IFNULL(
  42. c.now_city_id,(
  43. SELECT
  44. p.address_city_id
  45. FROM
  46. ${dbName}_common.f_operator p
  47. WHERE
  48. p.id = c.operator_id
  49. )) AS cityId,
  50. c.now_country_id AS countryId,
  51. c.now_street_id AS streetId,
  52. d.created_date AS createdDate
  53. FROM
  54. ${dbName}_finance.c_card_acc_detail d
  55. LEFT JOIN ${dbName}_customer.c_customer_subsidy_${operatorId} c ON c.subsidy_customer_id = d.subsidy_customer_id
  56. WHERE
  57. d.yn = 0
  58. AND d.ENABLE = 1
  59. AND d.type = 2
  60. and ${ew.sqlSegment}
  61. </select>
  62. <select id="areaList" resultType="com.poteviohealth.cgp.common.integrated.partner.model.AreaDTO">
  63. select id,parent as parentId,name,tree_path, region_area_code,
  64. (LENGTH(tree_path) - LENGTH(replace(tree_path,',','')))-1 as `level`
  65. from ${dbName}_common.f_area
  66. where yn = 0
  67. and parent is not null
  68. and length(tree_path)-length(replace(tree_path,',','')) &lt;=4
  69. and (region_area_code like '37%' or
  70. region_area_code like '32%' or
  71. region_area_code like '11%' or
  72. region_area_code like '13%' or
  73. region_area_code like '21%' or
  74. region_area_code like '51%')
  75. </select>
  76. <select id="supplierStationEmployeeList"
  77. resultType="com.poteviohealth.cgp.statistics.model.outdto.SupplierStationEmployee">
  78. select station_id,employee_id from ${dbName}_common.f_supplier_station_employee where yn = 0
  79. </select>
  80. <select id="supplierStationList" resultType="com.poteviohealth.cgp.statistics.model.outdto.SupplierStation">
  81. select id,city,country,street from ${dbName}_common.f_supplier_station
  82. where yn = 0 and `level` >=2 and status = 1 and type = 1 and LENGTH(region_code) = 12
  83. </select>
  84. <select id="employeeList" resultType="com.poteviohealth.cgp.statistics.model.outdto.Employee">
  85. select id,age,gender from ${dbName}_common.f_employee
  86. where yn = 0
  87. and role_id_str like '%25%'
  88. and status = 1
  89. and age is not null
  90. and gender is not null
  91. </select>
  92. <select id="getOperatorList" resultType="java.lang.Integer">
  93. select id from ${dbName}_common.f_operator
  94. where yn = 0 and id>0 and enabled = 1 and check_status = 2
  95. </select>
  96. <select id="getSubsidyCustomerList"
  97. resultType="com.poteviohealth.cgp.common.integrated.customer.model.CustomerSubsidyDTO">
  98. SELECT
  99. c.subsidy_customer_id as subsidyCustomerId,
  100. c.customer_id as customerId,
  101. IFNULL(c.now_city_id,(select p.address_city_id from ${dbName}_common.f_operator p where p.id = c.operator_id)) as nowCityId,
  102. IFNULL(c.now_city_name,(select p.address_city_name from ${dbName}_common.f_operator p where p.id = c.operator_id)) as nowCityName,
  103. c.now_country_id as nowCountryId,
  104. c.now_country_name as nowCountryName,
  105. c.now_street_id as nowStreetId,
  106. c.now_street_name as nowStreetName,
  107. c.customer_sign_id as customerSignId,
  108. cs.customer_type_id as customerTypeId,
  109. cs.customer_type as customerType,
  110. c.age as age,
  111. c.sex as sex,
  112. if(sum(IF( d.settlement = 1, 1, 0 ) )>0,1,0) as category
  113. FROM
  114. ${dbName}_finance.c_card_acc_detail d
  115. ,${dbName}_customer.c_customer_subsidy_${operatorId} c
  116. ,${dbName}_customer.c_customer_subsidy_supplier_${operatorId} cs
  117. where c.subsidy_customer_id = d.subsidy_customer_id
  118. and cs.subsidy_customer_id = c.subsidy_customer_id
  119. and c.yn = 0 AND d.yn = 0 AND cs.yn = 0
  120. and cs.enabled = 1
  121. and ${ew.sqlSegment}
  122. GROUP BY c.subsidy_customer_id
  123. </select>
  124. <select id="orderServiceCustomerList"
  125. resultType="com.poteviohealth.cgp.common.integrated.customer.model.CustomerServiceParams">
  126. SELECT
  127. IFNULL(c.now_city_id,(select p.address_city_id from ${dbName}_common.f_operator p where p.id = c.operator_id)) as cityId,
  128. IFNULL(c.now_country_id,-1) AS countryId,
  129. IFNULL(c.now_street_id,-1) AS streetId,
  130. count(DISTINCT c.customer_id) as customerNum,
  131. CONCAT(',',c.customer_type_id,',') as customerTypeId
  132. FROM
  133. ${dbName}_customer.c_customer_subsidy_${operatorId} c
  134. join (select subsidy_customer_id from ${dbName}_customer.c_customer_subsidy_supplier_${operatorId} where yn =0 and enabled = 1 group by subsidy_customer_id) csp
  135. on c.subsidy_customer_id = csp.subsidy_customer_id
  136. LEFT JOIN ${dbName}_order.o_order_${operatorId} o ON o.customer_id = c.customer_id
  137. WHERE
  138. o.order_status = 6
  139. AND o.order_type = 2
  140. and c.yn =0
  141. and o.yn = 0
  142. GROUP BY c.now_street_id,c.customer_type_id;
  143. </select>
  144. <select id="getSubsidyCustomerMealList" resultType="com.poteviohealth.cgp.statistics.model.outdto.Customer">
  145. select IFNULL(now_city_id,(select p.address_city_id from ${dbName}_common.f_operator p where p.id = operator_id)) as nowCityId,
  146. IFNULL(now_country_id,-1) AS nowCountryId,
  147. IFNULL(now_street_id,-1) AS nowStreetId
  148. from ${dbName}_customer.c_customer_subsidy_${operatorId}
  149. where yn = 0
  150. and ${ew.sqlSegment}
  151. </select>
  152. <select id="queryOrderIntegrationData"
  153. resultType="com.poteviohealth.cgp.statistics.model.outdto.OrderIntegrationData">
  154. SELECT o.order_id as orderId,o.city_id as cityId,o.country_id as countryId,o.street_id as streetId,o.visit_status as visitStatus
  155. ,o.customer_id as customerId,o.finish_time as finishTime,od.product_category_id as productCategoryId,v.qualified as qualified,
  156. v.result as result FROM ${dbName}_order.o_order_${operatorId} o,${dbName}_order.o_order_detail_${operatorId} od,${dbName}_order.o_visit_${operatorId} v
  157. where o.order_id = od.order_id
  158. and v.order_id = o.order_id
  159. and o.yn= 0 and v.yn = 0
  160. and o.order_status = 6
  161. and o.order_type = 2
  162. and o.city_id is not null
  163. and o.country_id is not null
  164. and o.street_id is not null
  165. and o.finish_time is not null
  166. and od.product_category_id is not null
  167. and ${ew.sqlSegment}
  168. group by o.order_id
  169. </select>
  170. <select id="getAllCategory" resultType="com.poteviohealth.cgp.common.integrated.ListParams">
  171. select id,name,parent_id as `key` from ${dbName}_common.f_category where yn = 0
  172. </select>
  173. <select id="integralTransactionList" resultType="com.poteviohealth.cgp.statistics.model.outdto.IntegralTransaction">
  174. select num,integral,merchant_id,merchant_name from ${dbName}_customer.c_integral_transaction_${operatorId} where yn =0 and type = 0
  175. </select>
  176. <select id="integralProductList" resultType="com.poteviohealth.cgp.statistics.model.outdto.IntegralProduct">
  177. select merchant_id from ${dbName}_customer.c_integral_product where yn =0 and type = 0 and own_review = 1
  178. </select>
  179. <select id="getStationMerchantList"
  180. resultType="com.poteviohealth.cgp.statistics.model.outdto.StationMerchant">
  181. select id,name,status,type,city,country,street,supplier_id,country_name,street_name from ${dbName}_common.f_station_merchant where yn = 0
  182. </select>
  183. <select id="queryIntegralProduct" resultType="com.poteviohealth.cgp.statistics.model.outdto.Product">
  184. select provider_id,parent_category_id from ${dbName}_product.p_product where operator_id = #{operatorId} and yn = 0 and own_status = 1 and tags like '%8962319%'
  185. </select>
  186. <select id="getIntegralCardAccOperatorIdList" resultType="java.lang.Integer">
  187. select operator_id from ${dbName}_finance.c_card_acc_detail where yn = 0 and type = 2 and enable = 1 and ${ew.sqlSegment} group by operator_id
  188. </select>
  189. <select id="getIntegralCardDetailOperatorIdList" resultType="java.lang.Integer">
  190. select operator_id from ${dbName}_finance.c_card_acc_detail where yn = 0 and type = 2 and enable = 1 group by operator_id
  191. </select>
  192. <select id="orderExcel" resultType="com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO">
  193. SELECT
  194. o.id as id,
  195. o.supplier_name as supplierName,
  196. o.order_id as orderId,
  197. o.sn as sn,
  198. o.customer_name as customerName,
  199. o.id_number as idNumber,
  200. o.name as name,
  201. o.phone as phone,
  202. o.address as address,
  203. o.product_string as productString,
  204. o.service_name as serviceName,
  205. o.service_sku_name as serviceSkuName,
  206. o.service_num as serviceNum,
  207. TRUNCATE(IFNULL(o.sum_order_price,0)/100.0,2) as sumOrderPrice,
  208. TRUNCATE(IFNULL(o.sum_price,0)/100.0,2) as sumPrice,
  209. o.pay_style as payStyle,
  210. o.reservation_time as reservationTime,
  211. o.pay_status as payStatus,
  212. o.order_style as orderStyle,
  213. o.order_status as orderStatus,
  214. DATE_FORMAT(o.order_time, '%Y-%m-%d %H:%i') as orderTime,
  215. o.home_time as homeTime,
  216. o.send_time as sendTime,
  217. o.pickup_time as pickupTime,
  218. o.employee_name as employeeName,
  219. DATE_FORMAT(o.start_time, '%Y-%m-%d %H:%i') as startTime,
  220. DATE_FORMAT(o.end_time, '%Y-%m-%d %H:%i') as endTime,
  221. TRUNCATE(IFNULL(o.settlement_price_sum,0)/100.0,2) as settlementPriceSum,
  222. o.pay_account as payAccount,
  223. o.service_station_name as serviceStationName,
  224. o.group_leader_name as groupLeaderName,
  225. o.visit_reserve_date as visitReserveDate,
  226. o.station_name as stationName,
  227. o.belong as belong,
  228. o.supplier_one_name as supplierOneName,
  229. o.contract_no as contractNo,
  230. TRUNCATE(IFNULL(o.consignment_price_sum,0)/100.0,2) as consignmentPriceSum,
  231. o.review_reason as reviewReason,
  232. TRUNCATE(IFNULL(o.pay_price,0)/100.0,2) as payPrice,
  233. TRUNCATE(IFNULL(o.card_price,0)/100.0,2) as cardPrice,
  234. TRUNCATE(IFNULL(o.subsidy_price,0)/100.0,2) as subsidyPrice,
  235. o.fund_price as fundPrice,
  236. od.tracking_code,
  237. od.tracking_company,
  238. od.man_hour,
  239. o.card_names as cardNameStr
  240. FROM
  241. ${dbName}_order.o_order_${operatorId} o
  242. left join ${dbName}_order.o_order_detail_${operatorId} od on o.order_id = od.order_id and od.yn=0
  243. WHERE
  244. o.yn=0
  245. and o.id > #{start}
  246. and ${ew.sqlSegment}
  247. order by o.id
  248. limit 10000
  249. </select>
  250. <select id="orderPageListSize" resultType="java.lang.Integer">
  251. SELECT count(*)
  252. FROM
  253. ${dbName}_order.o_order_${operatorId} o
  254. WHERE o.yn = 0
  255. and ${ew.sqlSegment}
  256. </select>
  257. <select id="orderPageListAllSize" resultType="java.lang.Integer">
  258. SELECT count(*)
  259. FROM
  260. ${dbName}_order.o_order_${operatorId} o
  261. left join ${dbName}_order.o_order_detail_${operatorId} od on o.order_id = od.order_id
  262. WHERE o.yn = 0
  263. AND od.yn = 0
  264. and ${ew.sqlSegment}
  265. </select>
  266. <select id="dishesOrderPageListAllSize" resultType="java.lang.Integer">
  267. SELECT count(*)
  268. FROM
  269. ${dbName}_order.o_dishes_order_${operatorId} o
  270. WHERE o.yn = 0
  271. and ${ew.sqlSegment}
  272. </select>
  273. <select id="dishesOrderExcel" resultType="com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO">
  274. SELECT
  275. id,
  276. customer_name,
  277. sn,
  278. customer_phone,
  279. product_string,
  280. DATE_FORMAT(order_time,'%Y-%m-%d %H:%i') AS orderTime,
  281. TRUNCATE ( sum_price/ 100.0, 2 ) AS sumPrice,
  282. TRUNCATE ( card_price/ 100.0, 2 ) AS cardPrice,
  283. TRUNCATE ( subsidy_price/ 100.0, 2 ) AS subsidyPrice,
  284. TRUNCATE ( pay_price/ 100.0, 2 ) AS payPrice,
  285. fund_price,
  286. '已支付' as payStatusStr,
  287. pay_account as payAccountStr,
  288. service_station_name
  289. FROM
  290. ${dbName}_order.o_dishes_order_${operatorId} o
  291. WHERE o.yn = 0
  292. and o.id > #{start}
  293. and ${ew.sqlSegment}
  294. order by o.id
  295. limit 10000
  296. </select>
  297. <select id="costOrderPageListAllSize" resultType="java.lang.Integer">
  298. SELECT count(*)
  299. FROM
  300. ${dbName}_order.o_order_cost_${operatorId} o
  301. WHERE o.yn = 0
  302. and ${ew.sqlSegment}
  303. </select>
  304. <select id="costOrderExcel" resultType="com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO">
  305. SELECT
  306. o.id,
  307. o.sn,
  308. o.category_name,
  309. o.cost_year,
  310. o.customer_name,
  311. o.customer_type,
  312. o.station_name,
  313. o.settlement_attribution,
  314. o.service_station_name,
  315. o.country_name,
  316. o.address,
  317. o.employee_name,
  318. o.service_name,
  319. DATE_FORMAT(o.order_time,'%Y-%m-%d %H:%i') AS orderTime,
  320. DATE_FORMAT(o.end_time,'%Y-%m-%d %H:%i') AS endTime,
  321. case when o.revenue_status = 1 then '未核算' else '已核算' end as revenueStatusStr,
  322. TRUNCATE (o.sign_price/ 100.0, 2 ) AS signPrice,
  323. o.man_hour,
  324. o.num,
  325. TRUNCATE (o.price/ 100.0, 2 ) AS price,
  326. TRUNCATE (o.labor/ 100.0, 2 ) as labor,
  327. TRUNCATE (o.standard/ 100.0, 2 ) as standard,
  328. TRUNCATE (o.adjustment/ 100.0, 2 ) as adjustment,
  329. TRUNCATE (o.actual/ 100.0, 2 ) as actual,
  330. TRUNCATE (o.income/ 100.0, 2 ) as income,
  331. TRUNCATE (o.money/ 100.0, 2 ) as money,
  332. DATE_FORMAT(o.revenue_date,'%Y-%m-%d %H:%i') AS revenueDate,
  333. o.remark,
  334. o.transaction_id,
  335. TRUNCATE (o.pay_price/ 100.0, 2 ) as payPrice
  336. FROM
  337. ${dbName}_order.o_order_cost_${operatorId} o
  338. WHERE o.yn = 0
  339. and o.id > #{start}
  340. and ${ew.sqlSegment}
  341. order by o.id
  342. limit 10000
  343. </select>
  344. <select id="pageCardListSize" resultType="java.lang.Integer">
  345. select count(*) from (
  346. select count(d.id)
  347. from ${dbName}_finance.c_card_acc_detail d
  348. left join (SELECT d.id,
  349. SUBSTRING_INDEX( SUBSTRING_INDEX( d.station_ids, ',', b.id + 1 ), ',', -1 ) AS stationId
  350. FROM ${dbName}_finance.c_card_acc_detail d INNER JOIN t_number b ON b.id &lt;(
  351. LENGTH( d.station_ids ) - LENGTH( REPLACE(d.station_ids,',','') ) + 1
  352. )
  353. where d.yn = 0 and d.type = 1 and d.station_ids != '' and ${ew.sqlSegment} ) a
  354. on d.id = a.id
  355. <if test="queryParam.stationIds!=null and queryParam.stationIds.size()>0">
  356. and a.stationId in
  357. <foreach collection="queryParam.stationIds" item="item" separator="," open="(" close=")">
  358. #{item}
  359. </foreach>
  360. </if>
  361. where d.yn = 0 and d.type = 1 and d.station_ids != ''
  362. and ${ew.sqlSegment}
  363. group by d.id) t
  364. </select>
  365. <select id="pageCardList" resultType="com.poteviohealth.cgp.common.integrated.finance.model.MemberPlanDTO">
  366. select d.id,d.name,d.phone,d.id_number,d.category_name,d.type_name,d.customer_address,d.customer_type_name,
  367. case when d.enable =1 then '启用' else '停用' end as enabled,TRUNCATE(d.balance/100,2) as balance
  368. from ${dbName}_finance.c_card_acc_detail d
  369. left join (SELECT d.id,
  370. SUBSTRING_INDEX( SUBSTRING_INDEX( d.station_ids, ',', b.id + 1 ), ',', -1 ) AS stationId
  371. FROM ${dbName}_finance.c_card_acc_detail d INNER JOIN t_number b ON b.id &lt;(
  372. LENGTH( d.station_ids ) - LENGTH( REPLACE(d.station_ids,',','') ) + 1
  373. )
  374. where d.yn = 0 and d.type = 1 and d.station_ids != '' and ${ew.sqlSegment} ) a
  375. on d.id = a.id
  376. <if test="queryParam.stationIds!=null and queryParam.stationIds.size()>0">
  377. and a.stationId in
  378. <foreach collection="queryParam.stationIds" item="item" separator="," open="(" close=")">
  379. #{item}
  380. </foreach>
  381. </if>
  382. where d.yn = 0 and d.type = 1 and d.station_ids != ''
  383. and d.id > #{start}
  384. and ${ew.sqlSegment}
  385. group by d.id
  386. order by d.id
  387. limit 10000
  388. </select>
  389. </mapper>