RecommendMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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.zhentao.mapper.RecommendMapper">
  4. <resultMap id="RecommendUserMap" type="com.zhentao.vo.RecommendUserVO">
  5. <result column="user_id" property="userId"/>
  6. <result column="nickname" property="nickname"/>
  7. <result column="gender" property="gender"/>
  8. <result column="province_id" property="provinceId"/>
  9. <result column="city_id" property="cityId"/>
  10. <result column="area_id" property="areaId"/>
  11. <result column="height" property="height"/>
  12. <result column="weight" property="weight"/>
  13. <result column="education_level" property="educationLevel"/>
  14. <result column="salary_range" property="salaryRange"/>
  15. <result column="hobby" property="hobby"/>
  16. <result column="star" property="star"/>
  17. <result column="animal" property="animal"/>
  18. <result column="school_name" property="schoolName"/>
  19. <result column="job_title" property="jobTitle"/>
  20. <result column="avatar_url" property="avatarUrl"/>
  21. <result column="compatibility_score" property="compatibilityScore"/>
  22. <result column="last_active_at" property="lastActiveAt"/>
  23. </resultMap>
  24. <select id="selectRecommendedUsers" resultMap="RecommendUserMap">
  25. <![CDATA[
  26. SELECT
  27. u.user_id,
  28. u.nickname,
  29. u.gender,
  30. p.province_id,
  31. p.city_id,
  32. p.area_id,
  33. p.height,
  34. p.weight,
  35. p.education_level,
  36. p.salary_range,
  37. p.hobby,
  38. p.star,
  39. p.animal,
  40. p.school_name,
  41. p.job_title,
  42. u.avatar_url,
  43. (
  44. ROUND(
  45. (
  46. 1.0 * (COALESCE(p.authenticity_score, 0) / 100.0)
  47. + 0.9 * (
  48. CASE WHEN #{oppoOnly} = 1 AND u.gender <> cur.cu_gender THEN 1
  49. WHEN #{oppoOnly} = 0 THEN 1
  50. ELSE 0 END
  51. )
  52. + 0.8 * (
  53. CASE
  54. WHEN ABS(TIMESTAMPDIFF(YEAR, u.birth_date, cur.cu_birth)) <= 3 THEN 1
  55. WHEN ABS(TIMESTAMPDIFF(YEAR, u.birth_date, cur.cu_birth)) <= 5 THEN 0.5
  56. ELSE 0
  57. END
  58. )
  59. + 0.7 * LEAST(
  60. (
  61. CASE
  62. WHEN p.salary_range >= cur.cu_salary THEN 1
  63. WHEN p.salary_range = cur.cu_salary - 1 THEN 0.5
  64. ELSE 0
  65. END
  66. ),
  67. (
  68. CASE
  69. WHEN cur.cu_salary >= p.salary_range THEN 1
  70. WHEN cur.cu_salary = p.salary_range - 1 THEN 0.5
  71. ELSE 0
  72. END
  73. )
  74. )
  75. + 0.6 * LEAST(
  76. (
  77. CASE
  78. WHEN p.education_level >= cur.cu_edu THEN 1
  79. WHEN p.education_level = cur.cu_edu - 1 THEN 0.5
  80. ELSE 0
  81. END
  82. ),
  83. (
  84. CASE
  85. WHEN cur.cu_edu >= p.education_level THEN 1
  86. WHEN cur.cu_edu = p.education_level - 1 THEN 0.5
  87. ELSE 0
  88. END
  89. )
  90. )
  91. + 0.5 * (
  92. CASE
  93. WHEN p.height IS NOT NULL AND cur.cu_height IS NOT NULL THEN
  94. CASE
  95. WHEN ABS(p.height - cur.cu_height) <= 5 THEN 1
  96. WHEN ABS(p.height - cur.cu_height) <= 10 THEN 0.5
  97. ELSE 0
  98. END
  99. ELSE 0
  100. END
  101. )
  102. + 0.4 * (
  103. CASE WHEN JSON_OVERLAPS(p.hobby, cur.cu_hobby) THEN 1 ELSE 0 END
  104. )
  105. + 0.3 * (
  106. CASE WHEN p.city_id = cur.cu_city THEN 1
  107. WHEN p.province_id = cur.cu_province THEN 0.5 ELSE 0 END
  108. )
  109. + 0.2 * (
  110. CASE
  111. WHEN p.star IS NOT NULL AND cur.cu_star IS NOT NULL THEN
  112. CASE
  113. WHEN p.star = cur.cu_star THEN 1
  114. WHEN (
  115. (CASE
  116. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  117. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  118. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  119. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  120. ELSE 0
  121. END)
  122. =
  123. (CASE
  124. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  125. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  126. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  127. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  128. ELSE 0
  129. END)
  130. ) THEN 0.75
  131. WHEN (
  132. (
  133. (CASE
  134. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  135. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  136. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  137. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  138. ELSE 0
  139. END) = 1
  140. AND
  141. (CASE
  142. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  143. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  144. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  145. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  146. ELSE 0
  147. END) = 3
  148. ) OR (
  149. (CASE
  150. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  151. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  152. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  153. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  154. ELSE 0
  155. END) = 3
  156. AND
  157. (CASE
  158. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  159. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  160. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  161. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  162. ELSE 0
  163. END) = 1
  164. ) OR (
  165. (CASE
  166. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  167. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  168. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  169. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  170. ELSE 0
  171. END) = 2
  172. AND
  173. (CASE
  174. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  175. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  176. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  177. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  178. ELSE 0
  179. END) = 4
  180. ) OR (
  181. (CASE
  182. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  183. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  184. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  185. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  186. ELSE 0
  187. END) = 4
  188. AND
  189. (CASE
  190. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  191. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  192. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  193. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  194. ELSE 0
  195. END) = 2
  196. )
  197. ) THEN 0.5
  198. ELSE 0
  199. END
  200. ELSE 0
  201. END
  202. )
  203. + 0.1 * (
  204. CASE
  205. WHEN p.animal IS NOT NULL AND cur.cu_animal IS NOT NULL THEN
  206. CASE
  207. WHEN p.animal = cur.cu_animal THEN 1
  208. WHEN (
  209. (CASE
  210. WHEN p.animal IN ('猴','鼠','龙') THEN 1
  211. WHEN p.animal IN ('猪','兔','羊') THEN 2
  212. WHEN p.animal IN ('虎','马','狗') THEN 3
  213. WHEN p.animal IN ('蛇','鸡','牛') THEN 4
  214. ELSE 0
  215. END)
  216. =
  217. (CASE
  218. WHEN cur.cu_animal IN ('猴','鼠','龙') THEN 1
  219. WHEN cur.cu_animal IN ('猪','兔','羊') THEN 2
  220. WHEN cur.cu_animal IN ('虎','马','狗') THEN 3
  221. WHEN cur.cu_animal IN ('蛇','鸡','牛') THEN 4
  222. ELSE 0
  223. END)
  224. ) THEN 0.75
  225. WHEN (
  226. (p.animal = '鼠' AND cur.cu_animal = '牛') OR (p.animal = '牛' AND cur.cu_animal = '鼠') OR
  227. (p.animal = '虎' AND cur.cu_animal = '猪') OR (p.animal = '猪' AND cur.cu_animal = '虎') OR
  228. (p.animal = '兔' AND cur.cu_animal = '狗') OR (p.animal = '狗' AND cur.cu_animal = '兔') OR
  229. (p.animal = '龙' AND cur.cu_animal = '鸡') OR (p.animal = '鸡' AND cur.cu_animal = '龙') OR
  230. (p.animal = '蛇' AND cur.cu_animal = '猴') OR (p.animal = '猴' AND cur.cu_animal = '蛇') OR
  231. (p.animal = '马' AND cur.cu_animal = '羊') OR (p.animal = '羊' AND cur.cu_animal = '马')
  232. ) THEN 0.75
  233. ELSE 0
  234. END
  235. ELSE 0
  236. END
  237. )
  238. + 0.05 * (
  239. CASE WHEN p.school_name IS NOT NULL AND cur.cu_school IS NOT NULL AND p.school_name = cur.cu_school THEN 1 ELSE 0 END
  240. )
  241. + 0.05 * (
  242. CASE
  243. WHEN p.job_title IS NOT NULL AND cur.cu_job_title IS NOT NULL THEN
  244. CASE
  245. WHEN p.job_title = cur.cu_job_title THEN 1
  246. WHEN p.job_title LIKE CONCAT('%', cur.cu_job_title, '%') OR cur.cu_job_title LIKE CONCAT('%', p.job_title, '%') THEN 0.5
  247. ELSE 0
  248. END
  249. ELSE 0
  250. END
  251. )
  252. + 0.05 * (
  253. CASE
  254. WHEN p.weight IS NOT NULL AND cur.cu_weight IS NOT NULL THEN
  255. CASE
  256. WHEN ABS(p.weight - cur.cu_weight) <= 5 THEN 1
  257. WHEN ABS(p.weight - cur.cu_weight) <= 10 THEN 0.5
  258. ELSE 0
  259. END
  260. ELSE 0
  261. END
  262. )
  263. + 0.05 * (
  264. CASE
  265. WHEN u.last_active_at >= NOW() - INTERVAL 7 DAY THEN 1
  266. WHEN u.last_active_at >= NOW() - INTERVAL 30 DAY THEN 0.4
  267. ELSE 0
  268. END
  269. )
  270. ) / 5.7 * 100
  271. , 2)
  272. ) AS compatibility_score,
  273. u.last_active_at
  274. FROM users u
  275. LEFT JOIN user_profile p ON p.user_id = u.user_id
  276. CROSS JOIN (
  277. SELECT
  278. u.user_id AS cu_id,
  279. u.gender AS cu_gender,
  280. u.birth_date AS cu_birth,
  281. COALESCE(up.city_id, NULL) AS cu_city,
  282. COALESCE(up.province_id, NULL) AS cu_province,
  283. COALESCE(up.height, NULL) AS cu_height,
  284. COALESCE(up.weight, NULL) AS cu_weight,
  285. COALESCE(up.education_level, NULL) AS cu_edu,
  286. COALESCE(up.salary_range, NULL) AS cu_salary,
  287. COALESCE(up.hobby, NULL) AS cu_hobby,
  288. COALESCE(up.star, NULL) AS cu_star,
  289. COALESCE(up.animal, NULL) AS cu_animal,
  290. COALESCE(up.school_name, NULL) AS cu_school,
  291. COALESCE(up.job_title, NULL) AS cu_job_title
  292. FROM users u
  293. LEFT JOIN user_profile up ON up.user_id = u.user_id
  294. WHERE u.user_id = #{userId}
  295. AND u.gender IS NOT NULL
  296. AND u.gender <> 0
  297. ) cur
  298. WHERE cur.cu_id IS NOT NULL
  299. AND cur.cu_gender IS NOT NULL
  300. AND cur.cu_gender <> 0
  301. AND u.user_id <> cur.cu_id
  302. AND u.status = 1
  303. AND u.gender IS NOT NULL
  304. AND u.gender <> 0
  305. AND (
  306. #{oppoOnly} = 0
  307. OR u.gender <> cur.cu_gender
  308. )
  309. ORDER BY compatibility_score DESC, u.last_active_at DESC
  310. LIMIT #{limit}
  311. ]]>
  312. </select>
  313. <select id="selectByRules" resultMap="RecommendUserMap">
  314. SELECT
  315. u.user_id,
  316. u.nickname,
  317. u.gender,
  318. u.avatar_url,
  319. p.province_id,
  320. p.city_id,
  321. p.area_id,
  322. p.height,
  323. p.education_level,
  324. p.salary_range,
  325. p.star,
  326. p.animal,
  327. p.hobby,
  328. (
  329. ROUND(
  330. (
  331. 1.0 * (COALESCE(p.authenticity_score, 0) / 100.0)
  332. + 0.9 * (
  333. CASE WHEN u.gender &lt;&gt; cur.cu_gender THEN 1 ELSE 0.2 END
  334. ) /* 不同性别权重更高,相同性别给予较低分 */
  335. + 0.8 * (
  336. CASE
  337. WHEN ABS(TIMESTAMPDIFF(YEAR, u.birth_date, cur.cu_birth)) &lt;= 3 THEN 1
  338. WHEN ABS(TIMESTAMPDIFF(YEAR, u.birth_date, cur.cu_birth)) &lt;= 5 THEN 0.5
  339. ELSE 0
  340. END
  341. )
  342. + 0.7 * LEAST(
  343. (
  344. CASE
  345. WHEN p.salary_range &gt;= cur.cu_salary THEN 1
  346. WHEN p.salary_range = cur.cu_salary - 1 THEN 0.5
  347. ELSE 0
  348. END
  349. ),
  350. (
  351. CASE
  352. WHEN cur.cu_salary &gt;= p.salary_range THEN 1
  353. WHEN cur.cu_salary = p.salary_range - 1 THEN 0.5
  354. ELSE 0
  355. END
  356. )
  357. )
  358. + 0.6 * LEAST(
  359. (
  360. CASE
  361. WHEN p.education_level &gt;= cur.cu_edu THEN 1
  362. WHEN p.education_level = cur.cu_edu - 1 THEN 0.5
  363. ELSE 0
  364. END
  365. ),
  366. (
  367. CASE
  368. WHEN cur.cu_edu &gt;= p.education_level THEN 1
  369. WHEN cur.cu_edu = p.education_level - 1 THEN 0.5
  370. ELSE 0
  371. END
  372. )
  373. )
  374. + 0.5 * (
  375. CASE
  376. WHEN p.height IS NOT NULL AND cur.cu_height IS NOT NULL THEN
  377. CASE
  378. WHEN ABS(p.height - cur.cu_height) &lt;= 5 THEN 1
  379. WHEN ABS(p.height - cur.cu_height) &lt;= 10 THEN 0.5
  380. ELSE 0
  381. END
  382. ELSE 0
  383. END
  384. )
  385. + 0.4 * (
  386. CASE WHEN JSON_OVERLAPS(p.hobby, cur.cu_hobby) THEN 1 ELSE 0 END
  387. )
  388. + 0.3 * (
  389. CASE WHEN p.city_id = cur.cu_city THEN 1
  390. WHEN p.province_id = cur.cu_province THEN 0.5 ELSE 0 END
  391. )
  392. + 0.2 * (
  393. CASE
  394. WHEN p.star IS NOT NULL AND cur.cu_star IS NOT NULL THEN
  395. CASE
  396. WHEN p.star = cur.cu_star THEN 1
  397. WHEN (
  398. (CASE
  399. WHEN p.star IN ('白羊座','狮子座','射手座') THEN 1
  400. WHEN p.star IN ('金牛座','处女座','摩羯座') THEN 2
  401. WHEN p.star IN ('双子座','天秤座','水瓶座') THEN 3
  402. WHEN p.star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  403. ELSE 0
  404. END)
  405. =
  406. (CASE
  407. WHEN cur.cu_star IN ('白羊座','狮子座','射手座') THEN 1
  408. WHEN cur.cu_star IN ('金牛座','处女座','摩羯座') THEN 2
  409. WHEN cur.cu_star IN ('双子座','天秤座','水瓶座') THEN 3
  410. WHEN cur.cu_star IN ('巨蟹座','天蝎座','双鱼座') THEN 4
  411. ELSE 0
  412. END)
  413. ) THEN 0.75
  414. ELSE 0
  415. END
  416. ELSE 0
  417. END
  418. )
  419. + 0.1 * (
  420. CASE
  421. WHEN p.animal IS NOT NULL AND cur.cu_animal IS NOT NULL THEN
  422. CASE WHEN p.animal = cur.cu_animal THEN 1 ELSE 0 END
  423. ELSE 0
  424. END
  425. )
  426. + 0.05 * (
  427. CASE WHEN p.school_name IS NOT NULL AND cur.cu_school IS NOT NULL AND p.school_name = cur.cu_school THEN 1 ELSE 0 END
  428. )
  429. + 0.05 * (
  430. CASE
  431. WHEN p.job_title IS NOT NULL AND cur.cu_job_title IS NOT NULL THEN
  432. CASE
  433. WHEN p.job_title = cur.cu_job_title THEN 1
  434. WHEN p.job_title LIKE CONCAT('%', cur.cu_job_title, '%') OR cur.cu_job_title LIKE CONCAT('%', p.job_title, '%') THEN 0.5
  435. ELSE 0
  436. END
  437. ELSE 0
  438. END
  439. )
  440. + 0.05 * (
  441. CASE
  442. WHEN p.weight IS NOT NULL AND cur.cu_weight IS NOT NULL THEN
  443. CASE
  444. WHEN ABS(p.weight - cur.cu_weight) &lt;= 5 THEN 1
  445. WHEN ABS(p.weight - cur.cu_weight) &lt;= 10 THEN 0.5
  446. ELSE 0
  447. END
  448. ELSE 0
  449. END
  450. )
  451. + 0.05 * (
  452. CASE
  453. WHEN u.last_active_at &gt;= NOW() - INTERVAL 7 DAY THEN 1
  454. WHEN u.last_active_at &gt;= NOW() - INTERVAL 30 DAY THEN 0.4
  455. ELSE 0
  456. END
  457. )
  458. ) / 5.7 * 100
  459. , 2)
  460. ) AS compatibility_score
  461. FROM users u
  462. JOIN user_profile p ON p.user_id = u.user_id
  463. CROSS JOIN (
  464. SELECT
  465. u.user_id AS cu_id,
  466. u.gender AS cu_gender,
  467. u.birth_date AS cu_birth,
  468. up.city_id AS cu_city,
  469. up.province_id AS cu_province,
  470. up.height AS cu_height,
  471. up.weight AS cu_weight,
  472. up.education_level AS cu_edu,
  473. up.salary_range AS cu_salary,
  474. up.hobby AS cu_hobby,
  475. up.star AS cu_star,
  476. up.animal AS cu_animal,
  477. up.school_name AS cu_school,
  478. up.job_title AS cu_job_title
  479. FROM users u
  480. LEFT JOIN user_profile up ON up.user_id = u.user_id
  481. WHERE u.user_id = #{q.userId}
  482. ) cur
  483. <where>
  484. u.status = 1
  485. AND u.gender IS NOT NULL
  486. AND u.gender &lt;&gt; 0
  487. <if test="q.userId != null">AND u.user_id &lt;&gt; #{q.userId}</if>
  488. AND (
  489. (#{q.gender} IS NOT NULL AND u.gender = #{q.gender})
  490. OR (#{q.gender} IS NULL AND (cur.cu_gender IS NOT NULL AND cur.cu_gender &lt;&gt; 0 AND u.gender &lt;&gt; cur.cu_gender))
  491. )
  492. <if test="q.provinceId != null">AND p.province_id = #{q.provinceId}</if>
  493. <if test="q.cityId != null">AND p.city_id = #{q.cityId}</if>
  494. <if test="q.areaId != null">AND p.area_id = #{q.areaId}</if>
  495. <if test="q.heightMin != null">AND p.height &gt;= #{q.heightMin}</if>
  496. <if test="q.heightMax != null">AND p.height &lt;= #{q.heightMax}</if>
  497. <if test="q.educationMin != null">AND p.education_level &gt;= #{q.educationMin}</if>
  498. <if test="q.salaryMin != null">AND p.salary_range &gt;= #{q.salaryMin}</if>
  499. <if test="q.star != null">AND p.star = #{q.star}</if>
  500. <if test="q.animal != null">AND p.animal = #{q.animal}</if>
  501. <if test="hobbyJson != null">AND JSON_OVERLAPS(p.hobby, #{hobbyJson})</if>
  502. <if test="birthMin != null">AND u.birth_date &gt;= #{birthMin}</if>
  503. <if test="birthMax != null">AND u.birth_date &lt;= #{birthMax}</if>
  504. <if test="excludeIds != null and excludeIds.size() &gt; 0">
  505. AND u.user_id NOT IN
  506. <foreach collection="excludeIds" item="id" open="(" separator="," close=")">#{id}</foreach>
  507. </if>
  508. </where>
  509. ORDER BY compatibility_score DESC, u.last_active_at DESC
  510. LIMIT #{limit} OFFSET #{offset}
  511. </select>
  512. <select id="selectAllProvinces" resultType="com.zhentao.pojo.Province">
  513. SELECT id, name FROM province ORDER BY id
  514. </select>
  515. <select id="selectAllCities" resultType="com.zhentao.pojo.City">
  516. SELECT id, name, province_id FROM city ORDER BY id
  517. </select>
  518. <select id="selectCitiesByProvince" resultType="com.zhentao.pojo.City">
  519. SELECT id, name, province_id FROM city WHERE province_id = #{provinceId} ORDER BY id
  520. </select>
  521. <select id="selectAreasByCity" resultType="com.zhentao.pojo.Area">
  522. SELECT id, name, city_id FROM area WHERE city_id = #{cityId} ORDER BY id
  523. </select>
  524. </mapper>