UserMaterialMapper.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.tld.mapper.UserMaterialMapper">
  5. <!-- 查询用户绑定物料信息 -->
  6. <select id="getUserMaterial" resultType="com.tld.model.UserMaterial">
  7. select
  8. distinct
  9. a.id,
  10. a.material_id,
  11. a.user_id,
  12. a.scrq,
  13. b.name as materialName,
  14. c.user_name as userName,
  15. b.code as wllbCode,
  16. c.real_name,
  17. a.modify_time,
  18. f.user_name as modifyUser
  19. from tld_user_material a
  20. left join tld_material b on a.material_id = b.code
  21. left join tld_user c on a.user_id = c.id
  22. left join tld_user f on a.modify_user = f.id
  23. <trim prefix="WHERE" prefixOverrides="and |or">
  24. <if test="materialId != null and materialId != ''">
  25. and a.material_id = #{materialId}
  26. </if>
  27. <if test="materialName != null and materialName != ''">
  28. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  29. </if>
  30. <if test="wllbCode != null and wllbCode != ''">
  31. and b.code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  32. </if>
  33. <if test="userName != null and userName != ''">
  34. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  35. </if>
  36. <if test="userId != null and userId != ''">
  37. and a.user_id = #{userId}
  38. </if>
  39. <if test="id != null and id != ''">
  40. and a.id = #{id}
  41. </if>
  42. </trim>
  43. order by a.id desc
  44. </select>
  45. <!-- 新增用户绑定物料信息 -->
  46. <insert id="addUserMaterial">
  47. insert into tld_user_material(material_id,user_id,scrq,modify_user,modify_time) value(#{materialId},#{userId},now(),#{modifyUser},now())
  48. </insert>
  49. <!-- 修改用户绑定物料信息 -->
  50. <update id="updateUserMaterial">
  51. update tld_user_material
  52. <set>
  53. <trim suffixOverrides=",">
  54. <if test="materialId != null and materialId != ''">
  55. material_id = #{materialId},
  56. </if>
  57. <if test="userId != null and userId != ''">
  58. user_id = #{userId},
  59. </if>
  60. modify_user = #{modifyUser},modify_time=now(),
  61. </trim>
  62. </set>
  63. where id = #{id}
  64. </update>
  65. <!-- 删除用户绑定物料信息 -->
  66. <delete id="delUserMaterial">
  67. delete from tld_user_material where id = #{id}
  68. </delete>
  69. <!-- 查询所有用户 -->
  70. <select id="getUser" resultType="com.tld.model.User">
  71. select
  72. a.id,
  73. a.code,
  74. a.user_name,
  75. a.password,
  76. a.real_name,
  77. a.email,
  78. a.landline,
  79. a.phone,
  80. a.department,
  81. a.role,
  82. b.menu
  83. from tld_user a
  84. left join tld_role b on a.role = b.id
  85. </select>
  86. <select id="getMaterial" resultType="java.lang.Integer">
  87. select COUNT(*) from tld_material where code = #{wllbCode}
  88. </select>
  89. <!--查询用户绑定物料信息导出-->
  90. <select id="Export" resultType="java.util.LinkedHashMap">
  91. SELECT DISTINCT
  92. b.CODE AS wllbCode,
  93. b.NAME AS materialName,
  94. c.user_name AS userName
  95. FROM
  96. tld_user_material a
  97. LEFT JOIN tld_material b ON a.material_id = b.CODE
  98. LEFT JOIN tld_user c ON a.user_id = c.id
  99. <trim prefix="WHERE" prefixOverrides="and |or">
  100. <if test="materialId != null and materialId != ''">
  101. and a.material_id = #{materialId}
  102. </if>
  103. <if test="materialName != null and materialName != ''">
  104. and b.name like CONCAT(CONCAT('%', #{materialName}), '%')
  105. </if>
  106. <if test="wllbCode != null and wllbCode != ''">
  107. and b.code like CONCAT(CONCAT('%', #{wllbCode}), '%')
  108. </if>
  109. <if test="userName != null and userName != ''">
  110. and c.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  111. </if>
  112. <if test="userId != null and userId != ''">
  113. and a.user_id = #{userId}
  114. </if>
  115. <if test="id != null and id != ''">
  116. and a.id = #{id}
  117. </if>
  118. </trim>
  119. order by a.id desc
  120. </select>
  121. </mapper>