TradeVisitorMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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.yc.ship.module.trade.dal.mysql.order.TradeVisitorMapper">
  4. <select id="selectVisitorListBySupplierOrder"
  5. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  6. select v.*,d.voucher_code
  7. FROM trade_detail_base db
  8. INNER JOIN trade_detail d on d.id = db.detail_id
  9. INNER JOIN trade_visitor v on v.detail_id = d.id
  10. <where>
  11. db.plat_supplier_order_id = #{platSupplierOrderId}
  12. </where>
  13. group by v.id
  14. order by v.detail_id
  15. </select>
  16. <select id="selectVisitorListBySpecType"
  17. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  18. select v.*
  19. FROM trade_detail_base db
  20. INNER JOIN trade_detail d on d.id = db.detail_id
  21. INNER JOIN trade_visitor v on v.detail_id = d.id
  22. <where>
  23. db.plat_supplier_order_id = #{platSupplierOrderId}
  24. and db.spec_type = #{specType}
  25. and db.product_base_id in
  26. <foreach collection="baseList" index="index" item="item" open="(" separator="," close=")">
  27. #{item}
  28. </foreach>
  29. </where>
  30. group by v.id
  31. order by v.detail_id
  32. </select>
  33. <select id="selectVisitorVoucherListByOrderId"
  34. resultType="com.yc.ship.module.trade.service.order.bo.TradeVisitorBO">
  35. select v.*,d.voucher_code,d.quantity_of_one
  36. FROM trade_detail d
  37. LEFT JOIN trade_visitor v on v.detail_id = d.id
  38. <where>
  39. d.order_id = #{orderId}
  40. </where>
  41. order by d.id
  42. </select>
  43. <select id="selectInsureVisitor"
  44. resultType="com.yc.ship.module.trade.service.order.bo.TradeVisitorBO">
  45. select tv.*,td.use_date
  46. from trade_detail td
  47. inner join trade_visitor tv on tv.detail_id = td.id
  48. <where>
  49. td.order_id =#{orderId} and td.voucher_status not in (4,5) and td.voucher_status>=1 and tv.is_insure =1
  50. and td.product_id=#{productId}
  51. </where>
  52. </select>
  53. <select id="selectContractVisitor"
  54. resultType="com.yc.ship.module.trade.service.order.bo.TradeVisitorBO">
  55. select distinct tv.*,td.use_date
  56. from trade_detail td
  57. inner join trade_visitor tv on tv.id = td.visitor_id
  58. <where>
  59. td.order_id =#{orderId} and td.voucher_status not in (4,5) and td.voucher_status>=1
  60. </where>
  61. </select>
  62. <select id="selectSupplierVisitor"
  63. resultType="com.yc.ship.module.trade.service.order.bo.TradeVisitorBO">
  64. select tdb.supplier_voucher_code, v.*
  65. from trade_detail_base tdb
  66. inner join trade_visitor v on v.detail_id = tdb.detail_id
  67. <where>
  68. tdb.plat_supplier_order_id = #{platSupplierOrderId}
  69. <if test="visitorIdList!=null">
  70. and v.id in
  71. <foreach collection="visitorIdList" item="item" separator="," open="(" close=")">
  72. #{item}
  73. </foreach>
  74. </if>
  75. </where>
  76. </select>
  77. <select id="selectShipVisitor"
  78. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  79. select t.product_type productType,v.*,t3.id_card jzCard,t3.arrive_time jzTime,t3.phone jzPhone,t3.address jzAddress
  80. , a.name nationalityName,t5.room_model_name roomModelName,
  81. if(t5.id is null,'内舱房',concat(t5.room_model_name,t5.floor,'楼(',t6.type_name,')')) as roomFullName,
  82. if(rr.id is null,'',concat(rrm.name,' | ',rr.room_num)) as roomName
  83. from trade_detail t inner join trade_visitor v on v.detail_id = t.id
  84. left join trade_order_jz_detail t3 on v.credential_no = t3.id_card and t3.deleted =0
  85. left join area a on v.nationality = a.id
  86. left join trade_order_room_model t5 on v.room_index_id = t5.room_index_id
  87. left join product_price_room_model_type t6 on t5.room_model_type_id=t6.id
  88. left join resource_room rr on v.final_room_id=concat(rr.id,'')
  89. left join resource_room_model rrm on rr.room_model_id = rrm.id
  90. where t.order_id = #{orderId} and v.deleted =0 and t.product_type =0 and t.deleted =0
  91. GROUP BY v.room_index_id,v.id
  92. order by v.room_index_id,v.id
  93. </select>
  94. <select id="selectRoomShipVisitor"
  95. resultType="com.yc.ship.module.product.api.dto.OrderRoomUseDTO">
  96. select room_model_id,floor,room_id,count(1) num from trade_visitor
  97. where order_id = #{orderId} and deleted =0
  98. group by room_model_id,floor,room_id
  99. </select>
  100. <select id="selectRefundRoomShipVisitor"
  101. resultType="com.yc.ship.module.product.api.dto.OrderRoomUseDTO">
  102. select t1.room_model_id,t1.floor,t1.room_id,count(distinct t1.id) num from trade_visitor t1
  103. inner join trade_detail t2 on t1.detail_id = t2.id
  104. inner join trade_refund_detail t3 on t2.id = t3.trade_detail_id
  105. where t3.refund_id = #{refundId} and deleted =0
  106. group by t1.room_model_id,t1.floor,t1.room_id
  107. </select>
  108. <select id="selectRoomShipVisitor2"
  109. resultType="com.yc.ship.module.product.api.dto.OrderRoomUseDTO">
  110. select room_model_id,floor,'' room_id,count(1) num from trade_order_room_model
  111. where order_id = #{orderId}
  112. group by room_model_id,floor
  113. </select>
  114. <select id="queryRelatedVisitor"
  115. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  116. SELECT v1.*, v2.id associatedVisitorId
  117. FROM trade_visitor v1
  118. INNER JOIN trade_visitor v2 ON v2.ota_detail_id = v1.detail_id
  119. WHERE v2.id in
  120. <foreach collection="visitorIds" item="item" separator="," open="(" close=")">
  121. #{item}
  122. </foreach>
  123. UNION ALL
  124. SELECT v1.*, v2.id associatedVisitorId
  125. FROM trade_visitor v1
  126. INNER JOIN trade_visitor v2 ON v2.detail_id = v1.ota_detail_id
  127. WHERE v2.id in
  128. <foreach collection="visitorIds" item="item" separator="," open="(" close=")">
  129. #{item}
  130. </foreach>
  131. </select>
  132. <select id="queryVisitorByOrderId" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeVisitorRespVO">
  133. SELECT v1.*,t3.name nationalityName FROM trade_visitor v1 INNER JOIN trade_detail v2 ON v1.id = v2.visitor_id
  134. left join area t3 on v1.nationality = t3.id
  135. WHERE v2.order_id = #{orderId} and v1.deleted = 0 and v2.deleted = 0 and v2.product_type = 0
  136. </select>
  137. <select id="selectVisitorListByDate" resultType="com.yc.ship.module.trade.service.order.bo.TradeVisitorBO">
  138. select tv.*,td.product_name,td.spec_type,td.use_date,prp.name planName
  139. from trade_detail td
  140. inner join trade_order tt on td.order_id = tt.id
  141. left join product_route_plan prp on tt.route_plan_id = prp.id
  142. inner join trade_visitor tv on td.id = tv.detail_id
  143. inner join trade_detail_base tdb on td.id = tdb.detail_id
  144. where td.use_date =#{useDate} and tv.credential_no is not null
  145. and tdb.project_code='boat'
  146. and tv.is_push is null
  147. and td.voucher_status in (1,2,4,8,9)
  148. <if test="orderId!=null">
  149. and td.order_id = #{orderId}
  150. </if>
  151. <if test="tenantId!=null">
  152. and td.tenant_id = #{tenantId}
  153. </if>
  154. GROUP BY td.id,tv.id
  155. order by tv.create_time asc
  156. </select>
  157. <select id="selectBoatVisitorListByRefund" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  158. select tv.*
  159. from trade_refund tr
  160. INNER JOIN trade_refund_detail_base trdb on trdb.refund_id = tr.id
  161. INNER JOIN trade_detail_base tdb on tdb.id = trdb.trade_detail_base_id
  162. INNER JOIN trade_visitor tv on tv.detail_id = trdb.trade_detail_id
  163. where tr.id = #{refundId} and tdb.project_code = 'boat'
  164. <if test="useDate!=null">
  165. and tdb.use_date = #{useDate}
  166. </if>
  167. GROUP BY tv.id
  168. </select>
  169. <select id="selectOrderVisitorCount" resultType="java.lang.Integer">
  170. select count(*) totalCount
  171. from trade_detail td
  172. INNER JOIN trade_visitor tv on tv.detail_id = td.id
  173. where td.order_id = #{orderId}
  174. and td.voucher_status !=5
  175. </select>
  176. <select id="selectShipByOrderIds"
  177. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  178. select * from trade_visitor where detail_id in (
  179. select id from trade_detail where order_id in
  180. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  181. #{item}
  182. </foreach>
  183. )
  184. </select>
  185. <select id="queryVisitorByVovageId" resultType="java.lang.Integer">
  186. select count(*) from trade_visitor t1 inner join trade_order t2 on t1.order_id=t2.id
  187. where t1.credential_no=#{credentialNo} and t2.voyage_id=#{voyageId} and t2.order_no!=#{orderNo}
  188. and t2.deleted = 0 and t1.deleted = 0 and t2.order_status in (15, 14, 13, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
  189. </select>
  190. <select id="selectListByVoyageId" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  191. select tv.*,if(pprmt.total_num &gt;=2 and pprmt.enable_share=0,1,0) as isHaveTogethers,if(pprmt.total_num =1 and pprmt.enable_share=0,1,0) as isAlone
  192. from trade_visitor tv
  193. join trade_order to1 on tv.order_id=to1.id and to1.deleted=0
  194. join trade_order_room_model torm on tv.room_index_id=torm.room_index_id and torm.deleted=0
  195. join product_price_room_model_type pprmt on torm.room_model_type_id = pprmt.id and pprmt.deleted=0
  196. where to1.voyage_id=#{voyageId} and to1.order_status=6 and tv.deleted=0
  197. and tv.room_index_id is not null
  198. and tv.room_model_id is not null
  199. and tv.floor is not null
  200. </select>
  201. <select id="selectListByVoyageIdAndRoomId"
  202. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  203. select tv.*
  204. from trade_visitor tv
  205. join trade_order b on tv.order_id=b.id and b.deleted=0
  206. where b.order_status=6 and b.voyage_id=#{voyageId} and if(tv.final_room_id is null,tv.init_room_id,tv.final_room_id)=#{roomId}
  207. </select>
  208. <select id="getExportVisitorList" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespExcelVO">
  209. select t1.order_no orderNo,t1.group_no groupNo,t1.order_status orderStatus,t1.source_name sourceName,t3.name name,
  210. t3.gender gender,t3.type visitorType,t3.credential_type credentialType,t3.credential_no credentialNo,
  211. t7.name nationality,t3.birthday birthday,t3.mobile mobile,t3.age age,t3.mobile mobile,t5.short_name roomModelName,t3.floor floor,t6.room_num roomName,t2.price price,t3.remark remark
  212. from trade_order t1 inner join trade_detail t2 on t1.id=t2.order_id and t2.product_type = 0 and t2.deleted = 0
  213. inner join trade_visitor t3 on t2.visitor_id=t3.id and t3.deleted =0
  214. left join trade_order_room_model t4 on t3.room_index_id=t4.room_index_id and t4.deleted=0
  215. left join resource_room_model t5 on t4.room_model_id = t5.id and t5.deleted=0
  216. left join resource_room t6 on t3.room_id = t6.id and t6.deleted=0
  217. left join area t7 on t3.nationality = t7.id
  218. where t1.order_status in (15, 14, 13, 11, 10, 12, 9, 8, 7, 6, 5, 4, 3, 2, 1)
  219. <if test="vo.orderNo != null and vo.orderNo != ''">
  220. AND t1.order_no = #{vo.orderNo}
  221. </if>
  222. <if test="vo.voyageId != null and vo.voyageId != ''">
  223. AND t1.voyage_id = #{vo.voyageId}
  224. </if>
  225. <if test="vo.otaId != null and vo.otaId != ''">
  226. AND t1.source_id = #{vo.otaId}
  227. </if>
  228. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  229. AND t1.source_id IN
  230. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  231. #{item}
  232. </foreach>
  233. </if>
  234. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  235. and t1.order_status in
  236. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  237. #{item}
  238. </foreach>
  239. </if>
  240. </select>
  241. <!-- 查询游客名单导出游客列表 -->
  242. <select id="selectTouristExportVisitor" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TouristExportVisitorVO">
  243. SELECT
  244. od.name AS sourceName,
  245. tor.order_no AS orderNo,
  246. tor.group_no AS groupNo,
  247. CASE WHEN rr.direction = 1 THEN '上水' ELSE '下水' END AS direction,
  248. CASE WHEN tjz.is_jz = 1 THEN '是' ELSE '否' END AS jz,
  249. DATE_FORMAT(pv.start_time, '%Y.%m.%d') AS travelDate,
  250. tor.pay_amount AS amount,
  251. tor.real_pay_amount AS payAmount,
  252. tor.deposi,
  253. tv.room_index_id AS roomIndexId,
  254. torm.room_model_name AS roomType,
  255. pprmt.type_name AS typeName ,
  256. tv.name,
  257. tv.gender,
  258. tv.birthday,
  259. tv.mobile,
  260. tv.order_id as orderId,
  261. tv.credential_type AS credentialType,
  262. tv.credential_no AS credentialNo,
  263. tv.type AS visitorType,
  264. tv.age,
  265. torm.floor as floor,
  266. a.name AS nationalityName,
  267. GROUP_CONCAT(ps.product_name) AS valueAddedService,
  268. tor.remark,
  269. tor.order_status as orderStatus
  270. FROM trade_visitor tv
  271. INNER JOIN trade_order tor ON tv.order_id = tor.id AND tor.deleted = 0
  272. INNER JOIN trade_detail td ON tv.id = td.visitor_id AND td.deleted = 0
  273. LEFT JOIN area a ON tv.nationality = a.id
  274. LEFT JOIN product_voyage pv ON tor.voyage_id = pv.id
  275. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  276. LEFT JOIN ota_distributor od ON tor.source_id = od.id
  277. LEFT JOIN trade_order_room_model torm ON tv.room_index_id = torm.room_index_id AND torm.deleted = 0
  278. left JOIN product_spu ps on ps.id = td.product_id
  279. left join trade_order_pay top ON top.order_id = tor.id and top.deleted = 0 and top.pay_status = 1
  280. left Join trade_order_jz tjz on tjz.order_id = tor.id
  281. left Join product_price_room_model_type pprmt on torm.room_model_type_id = pprmt.id
  282. WHERE tv.deleted = 0
  283. <if test="vo.orderNo != null and vo.orderNo != ''">
  284. AND tor.order_no = #{vo.orderNo}
  285. </if>
  286. <if test="vo.voyageId != null and vo.voyageId != ''">
  287. AND tor.voyage_id = #{vo.voyageId}
  288. </if>
  289. <if test="vo.shipId != null and vo.shipId != ''">
  290. AND pv.ship_id = #{vo.shipId}
  291. </if>
  292. <if test="vo.routeId != null and vo.routeId != ''">
  293. AND pv.route_id = #{vo.routeId}
  294. </if>
  295. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  296. AND pv.start_time &gt;= #{vo.travelDateStart}
  297. </if>
  298. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  299. AND pv.start_time &lt;= #{vo.travelDateEnd}
  300. </if>
  301. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  302. AND tor.create_time &gt;= #{vo.orderDateStart}
  303. </if>
  304. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  305. AND tor.create_time &lt;= #{vo.orderDateEnd}
  306. </if>
  307. <if test="vo.orderStatus != null and vo.orderStatus.size() > 0">
  308. AND tor.order_status IN
  309. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  310. #{item}
  311. </foreach>
  312. </if>
  313. <if test="vo.userName != null and vo.userName != ''">
  314. AND tv.name LIKE CONCAT('%', #{vo.userName}, '%')
  315. </if>
  316. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  317. AND tv.credential_no = #{vo.credentialNo}
  318. </if>
  319. <if test="vo.roomModelId != null and vo.roomModelId != ''">
  320. AND torm.room_model_id = #{vo.roomModelId}
  321. </if>
  322. <if test="vo.floor != null and vo.floor != ''">
  323. AND tv.floor = #{vo.floor}
  324. </if>
  325. <if test="vo.otaId != null and vo.otaId != ''">
  326. AND tor.source_id = #{vo.otaId}
  327. </if>
  328. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  329. AND tor.source_id IN
  330. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  331. #{item}
  332. </foreach>
  333. </if>
  334. <if test="vo.distributorId != null and vo.distributorId != ''">
  335. AND tor.source_id = #{vo.distributorId}
  336. </if>
  337. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  338. AND od.ota_category_id = #{vo.otaCateId}
  339. </if>
  340. <if test="vo.otaCateIds != null and vo.otaCateIds.size() > 0">
  341. AND od.ota_category_id IN
  342. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  343. #{item}
  344. </foreach>
  345. </if>
  346. <if test="vo.contactName != null and vo.contactName != ''">
  347. AND tor.link_man LIKE CONCAT('%', #{vo.contactName}, '%')
  348. </if>
  349. <if test="vo.mobile != null and vo.mobile != ''">
  350. AND tor.link_mobile = #{vo.mobile}
  351. </if>
  352. group by tv.id
  353. ORDER BY od.id ASC,tor.order_no ASC, tv.room_index_id ASC
  354. </select>
  355. <select id="selectPersonDesc" resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppPersonDescVO">
  356. select order_id,name, count(1) num
  357. from trade_visitor
  358. where deleted = 0 and order_id in
  359. <foreach item="item" collection="orderIds" separator="," open="(" close=")">
  360. #{item}
  361. </foreach>
  362. <if test="keyword != null and keyword != ''">
  363. and (mobile = #{keyword} or credential_no = #{keyword})
  364. </if>
  365. GROUP BY order_id
  366. </select>
  367. <select id="selectWithLeaderStatsByOrderIds"
  368. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderWithLeaderStatVO">
  369. select
  370. type,
  371. if(gender=0,'女','男') gender,
  372. count(1) num
  373. from trade_visitor
  374. where deleted = 0 and (type = 'with' or type = 'leader') and order_id in
  375. <foreach item="item" collection="orderIds" separator="," open="(" close=")">
  376. #{item}
  377. </foreach>
  378. GROUP BY type, gender
  379. </select>
  380. <select id="selectOrderCountryStatsByOrderIds"
  381. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalCountryVO">
  382. SELECT
  383. d1.country_id,
  384. d2.country_name,
  385. d1.adultNum,
  386. d1.childNum,
  387. d1.babyNum,
  388. d1.leaderNum,
  389. d1.withNum,
  390. d2.twoNum,
  391. d2.threeNum,
  392. d2.fourNum,
  393. d2.fiveNum,
  394. d2.sixNum
  395. FROM
  396. (
  397. SELECT
  398. a1.country_id,
  399. a1.country_name,
  400. sum( CASE WHEN a1.type = 'adultTake' OR a1.type = 'adultPlus' THEN a1.num ELSE 0 END ) AS adultNum,
  401. sum( CASE WHEN a1.type = 'childTake' OR a1.type = 'childNonTake' or a1.type = 'childPlus' THEN a1.num ELSE 0 END ) AS childNum,
  402. sum( CASE WHEN a1.type = 'babyTake' OR a1.type = 'babyNonTake' or a1.type = 'babyPlus' THEN a1.num ELSE 0 END ) AS babyNum,
  403. sum( CASE WHEN a1.type = 'leader' THEN a1.num ELSE 0 END ) AS leaderNum,
  404. sum( CASE WHEN a1.type = 'with' THEN a1.num ELSE 0 END ) AS withNum
  405. FROM
  406. (
  407. SELECT
  408. t1.nationality country_id,
  409. t2.`name` country_name,
  410. t1.type,
  411. count( t1.id ) num
  412. FROM
  413. trade_visitor t1
  414. LEFT JOIN area t2 ON t1.nationality = t2.id
  415. WHERE
  416. t1.deleted = 0
  417. AND t1.nationality IS NOT NULL
  418. AND t1.nationality != ''
  419. and t1.order_id in
  420. <foreach item="item" collection="orderIds" separator="," open="(" close=")">
  421. #{item}
  422. </foreach>
  423. GROUP BY
  424. t1.nationality,
  425. t1.type
  426. ) a1
  427. GROUP BY
  428. a1.country_id
  429. ORDER BY
  430. a1.country_id ASC
  431. ) d1
  432. LEFT JOIN (
  433. SELECT
  434. a1.country_id,
  435. a1.country_name,
  436. sum( CASE WHEN a1.floor = 2 THEN a1.num ELSE 0 END ) AS twoNum,
  437. sum( CASE WHEN a1.floor = 3 THEN a1.num ELSE 0 END ) AS threeNum,
  438. sum( CASE WHEN a1.floor = 4 THEN a1.num ELSE 0 END ) AS fourNum,
  439. sum( CASE WHEN a1.floor = 5 THEN a1.num ELSE 0 END ) AS fiveNum,
  440. sum( CASE WHEN a1.floor = 6 THEN a1.num ELSE 0 END ) AS sixNum
  441. FROM
  442. (
  443. SELECT
  444. t1.nationality country_id,
  445. t2.`name` country_name,
  446. t3.floor,
  447. count( t1.id ) num
  448. FROM
  449. trade_visitor t1
  450. LEFT JOIN area t2 ON t1.nationality = t2.id
  451. LEFT JOIN trade_order_room_model t3 ON t1.room_index_id = t3.room_index_id
  452. WHERE
  453. t1.deleted = 0
  454. AND t3.deleted = 0
  455. AND t1.nationality IS NOT NULL
  456. AND t1.nationality != ''
  457. and t1.order_id in
  458. <foreach item="item" collection="orderIds" separator="," open="(" close=")">
  459. #{item}
  460. </foreach>
  461. GROUP BY
  462. t1.nationality,
  463. t3.floor
  464. ) a1
  465. GROUP BY
  466. a1.country_id
  467. ORDER BY
  468. a1.country_id ASC
  469. ) d2 ON d1.country_id = d2.country_id
  470. ORDER BY
  471. d1.country_id ASC
  472. </select>
  473. <select id="selectPersonListByOrderId"
  474. resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppItineraryPersonVO">
  475. SELECT
  476. t1.id,
  477. t1.NAME,
  478. t1.mobile,
  479. t1.final_room_id,
  480. t2.room_num final_room_name,
  481. t1.init_room_id,
  482. t3.room_num init_room_name,
  483. t1.room_id,
  484. t4.room_num room_name
  485. FROM
  486. trade_visitor t1
  487. LEFT JOIN resource_room t2 ON t1.final_room_id = t2.id
  488. LEFT JOIN resource_room t3 ON t1.init_room_id = t3.id
  489. LEFT JOIN resource_room t4 ON t1.room_id = t4.id
  490. WHERE
  491. t1.deleted = 0
  492. AND t1.order_id = #{orderId}
  493. <if test="keyword != null and keyword != ''">
  494. AND (t1.mobile = #{keyword} or t1.credential_no = #{keyword})
  495. </if>
  496. </select>
  497. <select id="selectVisitorPage" resultType="com.yc.ship.module.trade.controller.admin.visitor.vo.VisitorRespVO">
  498. select t3.policy_no,t3.id insurance_id, t1.id,t1.order_id,t1.`name`,t1.gender,t1.credential_no,t1.nationality,t1.credential_type,t1.mobile,t1.is_insure,t1.insure_msg,t1.age,t2.order_no,t2.order_status,t4.id voyage_id,t4.name voyage_name from trade_visitor t1 LEFT JOIN trade_order t2 on t1.order_id = t2.id and t2.deleted = 0 LEFT JOIN trade_insurance t3 on t1.id = t3.visitor_id and t3.deleted = 0 LEFT JOIN product_voyage t4 on t2.voyage_id = t4.id and t4.deleted = 0
  499. where t1.deleted = 0 and t2.order_status in (1,6,13,14) and t4.id is not null
  500. <if test="vo.orderNo != null and vo.orderNo != ''">
  501. and t2.order_no = #{vo.orderNo}
  502. </if>
  503. <if test="vo.voyageId != null and vo.voyageId != ''">
  504. and t4.id = #{vo.voyageId}
  505. </if>
  506. <if test="vo.shipId != null and vo.shipId != ''">
  507. and t4.ship_id = #{vo.shipId}
  508. </if>
  509. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  510. and t1.credential_no = #{vo.credentialNo}
  511. </if>
  512. <if test="vo.name != null and vo.name != ''">
  513. and t1.name like concat('%',#{vo.name},'%')
  514. </if>
  515. <if test="vo.isInsure != null">
  516. and t1.is_insure = #{vo.isInsure}
  517. </if>
  518. order by t1.create_time asc
  519. </select>
  520. <delete id="deleteAllByOrderId">
  521. delete from trade_visitor where order_id = #{orderId}
  522. </delete>
  523. <select id="getValidSimpleVisitorInfoByVoyageIdAndOrderId"
  524. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  525. select a.id,a.name
  526. from trade_visitor a
  527. join trade_order b on a.order_id=b.id
  528. where a.deleted=0 and b.deleted=0
  529. and b.voyage_id=#{voyageId}
  530. and b.order_status in (1,6,9,13,14,15)
  531. <if test="orderId != null" >and a.order_id=#{orderId}</if>
  532. order by substring_index(b.order_no, '-', -1)*1 ,a.id
  533. </select>
  534. </mapper>