CustomerMapper.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.dayou.mapper.CustomerMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.Customer">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="name" property="name" />
  11. <result column="city" property="city" />
  12. <result column="county" property="county" />
  13. <result column="department" property="department" />
  14. <result column="position" property="position" />
  15. <result column="section" property="section" />
  16. <result column="mobile" property="mobile" />
  17. <result column="wechat_no" property="wechatNo" />
  18. <result column="QQ" property="qq" />
  19. <result column="level" property="level" />
  20. <result column="address" property="address" />
  21. <result column="user_id" property="userId" />
  22. </resultMap>
  23. <!-- 通用查询结果列 -->
  24. <sql id="Base_Column_List">
  25. id,
  26. deleted,
  27. created,
  28. modified,
  29. name, city, county, department, position, section, mobile, wechat_no, QQ, level, address,user_id
  30. </sql>
  31. <select id="getPage" parameterType="com.dayou.dto.CustomerDTO" resultType="com.dayou.dto.CustomerDTO">
  32. select c.*,u.name as userName
  33. from customer c left join user u on c.user_id = u.id
  34. <where>
  35. and c.deleted = 0 and u.deleted = 0
  36. <if test="keyword!=null and keyword!='' ">
  37. and(
  38. c.name like concat ('%',#{keyword},'%')
  39. or c.department like concat('%',#{keyword},'%')
  40. or c.position like concat('%',#{keyword},'%')
  41. or c.section like concat('%',#{keyword},'%')
  42. or JSON_EXTRACT(c.city,'$[1]') = (select id from districts where ext_name =#{keyword})
  43. or JSON_EXTRACT(c.city,'$[2]') = (select id from districts where ext_name =#{keyword})
  44. )
  45. </if>
  46. <if test="customer!=null and customer.name!=null and customer.name!='' ">
  47. and c.name like concat ('%',#{customer.name},'%')
  48. </if>
  49. <if test="customer!=null and customer.level!=null and customer.level!='' ">
  50. and c.level = #{customer.level}
  51. </if>
  52. <if test="customer!=null and customer.userIds!=null and customer.userIds.size!=0">
  53. and c.user_id in
  54. <foreach collection="customer.userIds" open="(" close=")" separator="," item="userId">
  55. #{userId}
  56. </foreach>
  57. </if>
  58. </where>
  59. </select>
  60. <select id="getList" parameterType="com.dayou.dto.CustomerDTO" resultType="com.dayou.dto.CustomerDTO">
  61. select c.*,u.name as userName
  62. from customer c left join user u on c.user_id = u.id
  63. <where>
  64. and c.deleted = 0 and u.deleted = 0
  65. <if test="customer!=null and customer.name!=null and customer.name!='' ">
  66. and c.name like concat ('%',#{customer.name},'%')
  67. </if>
  68. <if test="customer!=null and customer.level!=null and customer.level!='' ">
  69. and c.level = #{customer.level}
  70. </if>
  71. <if test="customer!=null and customer.userIds!=null and customer.userIds.size!=0">
  72. and c.user_id in
  73. <foreach collection="customer.userIds" open="(" close=")" separator="," item="userId">
  74. #{userId}
  75. </foreach>
  76. </if>
  77. </where>
  78. order by c.id DESC
  79. </select>
  80. </mapper>