EnterpriseMapper.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.enteprise.enterprise.mapper.EnterpriseMapper">
  6. <resultMap type="Enterprise" id="EnterpriseResult">
  7. <result property="id" column="id" />
  8. <result property="enterpriseName" column="enterprise_name" />
  9. <result property="location" column="location" />
  10. <result property="code" column="code" />
  11. </resultMap>
  12. <sql id="selectEnterpriseVo">
  13. select id, enterprise_name, location, code from enterprise
  14. </sql>
  15. <select id="selectEnterpriseList" parameterType="Enterprise" resultMap="EnterpriseResult">
  16. <include refid="selectEnterpriseVo"/>
  17. <where>
  18. <if test="enterpriseName != null and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
  19. <if test="location != null and location != ''"> and location = #{location}</if>
  20. <if test="code != null and code != ''"> and code = #{code}</if>
  21. <if test="typeNum != null and typeNum != ''"> and type_num = #{typeNum}</if>
  22. </where>
  23. </select>
  24. <select id="selectEnterpriseById" parameterType="Long" >
  25. SELECT a.id, a.enterprise_name enterpriseName, a.location, a.code, a.type_num typeNum, b.name typeName
  26. from enterprise a
  27. left join enterprise_type b
  28. on a.type_num = b.number
  29. where a.id = #{id}
  30. </select>
  31. <insert id="insertEnterprise" parameterType="Enterprise" useGeneratedKeys="true" keyProperty="id">
  32. insert into enterprise
  33. <trim prefix="(" suffix=")" suffixOverrides=",">
  34. <if test="enterpriseName != null and enterpriseName != ''">enterprise_name,</if>
  35. <if test="location != null">location,</if>
  36. <if test="code != null">code,</if>
  37. <if test="typeNum != null">type_num,</if>
  38. </trim>
  39. <trim prefix="values (" suffix=")" suffixOverrides=",">
  40. <if test="enterpriseName != null and enterpriseName != ''">#{enterpriseName},</if>
  41. <if test="location != null">#{location},</if>
  42. <if test="code != null">#{code},</if>
  43. <if test="typeNum != null">#{typeNum}</if>>
  44. </trim>
  45. </insert>
  46. <update id="updateEnterprise" parameterType="Enterprise">
  47. update enterprise
  48. <trim prefix="SET" suffixOverrides=",">
  49. <if test="enterpriseName != null and enterpriseName != ''">enterprise_name = #{enterpriseName},</if>
  50. <if test="location != null">location = #{location},</if>
  51. <if test="code != null">code = #{code},</if>
  52. <if test="typeNum != null">type_num = #{typeNum}</if>>
  53. </trim>
  54. where id = #{id}
  55. </update>
  56. <delete id="deleteEnterpriseById" parameterType="Long">
  57. delete from enterprise where id = #{id}
  58. </delete>
  59. <delete id="deleteEnterpriseByIds" parameterType="String">
  60. delete from enterprise where id in
  61. <foreach item="id" collection="array" open="(" separator="," close=")">
  62. #{id}
  63. </foreach>
  64. </delete>
  65. <select id="selectAllWithType" parameterType="Enterprise">
  66. SELECT a.id, a.enterprise_name enterpriseName, a.location, a.code, a.type_num typeNum, b.name typeName
  67. from enterprise a
  68. left join enterprise_type b
  69. on a.type_num = b.number
  70. <where>
  71. <if test="enterpriseName != null and enterpriseName != ''"> and a.enterprise_name like concat('%', #{enterpriseName}, '%')</if>
  72. <if test="location != null and location != ''"> and a.location = #{location}</if>
  73. <if test="code != null and code != ''"> and a.code = #{code}</if>
  74. <if test="typeNum != null and typeNum != ''"> and a.type_num = #{typeNum}</if>
  75. </where>
  76. </select>
  77. <insert id="insertOrUpdateBatch">
  78. INSERT INTO enterprise (enterprise_name, type_num)
  79. VALUES
  80. <foreach collection="list" item="item" separator=",">
  81. (#{item.enterpriseName}, #{item.typeNum})
  82. </foreach>
  83. ON DUPLICATE KEY UPDATE
  84. type_num = IF(VALUES(type_num) != '', VALUES(type_num), type_num)
  85. </insert>
  86. </mapper>