CompanyMapper.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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.dk.oauth.mapper.CompanyMapper">
  4. <!-- 通用查询列 -->
  5. <sql id="Base_Column_List">
  6. t.cp_id
  7. , t.cp_code, t.cp_name, t.svc_code, t.opening_date, t.grade_code, t.end_date, t.max_staff_num, t.cur_staff_num, t.flg_valid,
  8. t.remarks, t.op_create_time, t.op_create_user_id, t.op_update_time, t.op_update_user_id, t.op_app_code, t.op_timestamp, t.op_db_user,
  9. t.owner,t.cp_manager,t.cp_phone,t.cp_size,t.shop_size,t.feedback
  10. </sql>
  11. <resultMap type="com.dk.oauth.entity.CompanyResponse" id="ResultMap">
  12. <result column="cp_id" property="cpId"/>
  13. <result column="cp_code" property="cpCode"/>
  14. <result column="cp_name" property="cpName"/>
  15. <result column="svc_code" property="svcCode"/>
  16. <result column="svc_ip" property="svcIp"/>
  17. <result column="svc_port" property="svcPort"/>
  18. </resultMap>
  19. <!-- 通用查询映射结果 -->
  20. <resultMap id="BaseResultMap" type="com.dk.oauth.entity.Company">
  21. <id column="cp_id" property="cpId"/>
  22. <result column="cp_code" property="cpCode"/>
  23. <result column="cp_name" property="cpName"/>
  24. <result column="svc_code" property="svcCode"/>
  25. <result column="opening_date" property="openingDate" typeHandler="TimestampTypeHandler"/>
  26. <result column="grade_code" property="gradeCode"/>
  27. <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
  28. <result column="max_staff_num" property="maxStaffNum"/>
  29. <result column="cur_staff_num" property="curStaffNum"/>
  30. <result column="flg_valid" property="flgValid"/>
  31. <result column="remarks" property="remarks"/>
  32. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  33. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  34. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  35. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  36. <result column="op_app_code" property="opAppCode"/>
  37. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  38. <result column="op_db_user" property="opDbUser"/>
  39. <result column="owner" property="owner" typeHandler="UuidTypeHandler"/>
  40. <result column="cp_manager" property="cpManager"/>
  41. <result column="cp_phone" property="cpPhone"/>
  42. <result column="cp_size" property="cpSize"/>
  43. <result column="shop_size" property="shopSize"/>
  44. <result column="feedback" property="feedback"/>
  45. <result column="gradeName" property="gradeName"/>
  46. </resultMap>
  47. <!--获取企业信息-->
  48. <select id="getByCpId" resultMap="ResultMap">
  49. SELECT
  50. tac.cp_id ,
  51. tac.cp_code ,
  52. tac.cp_name,
  53. tac.svc_code ,
  54. tss.svc_ip,
  55. tss.svc_port
  56. FROM dkic_a.t_a_company tac
  57. LEFT JOIN dkic_a.t_s_service tss
  58. ON tac.svc_code = tss.svc_code
  59. AND tss.flg_valid
  60. where tac.cp_id = #{cpId} and (tac.end_date is null or tac.end_date > now()) and tac.flg_valid
  61. </select>
  62. <!-- 通用条件列 -->
  63. <sql id="Condition">
  64. <where>
  65. <if test="cpCode != null and cpCode != ''">
  66. AND t.cp_code = #{cpCode}
  67. </if>
  68. <if test="cpName != null and cpName != ''">
  69. AND t.cp_name = #{cpName}
  70. </if>
  71. <if test="svcCode != null and svcCode != ''">
  72. AND t.svc_code = #{svcCode}
  73. </if>
  74. <if test="openingDate != null">
  75. AND t.opening_date = #{openingDate}
  76. </if>
  77. <if test="gradeCode != null and gradeCode != ''">
  78. AND t.grade_code = #{gradeCode}
  79. </if>
  80. <if test="endDate != null">
  81. AND t.end_date = #{endDate}
  82. </if>
  83. <if test="maxStaffNum != null">
  84. AND t.max_staff_num = #{maxStaffNum}
  85. </if>
  86. <if test="curStaffNum != null">
  87. AND t.cur_staff_num = #{curStaffNum}
  88. </if>
  89. <if test="flgValid != null">
  90. AND t.flg_valid = #{flgValid}
  91. </if>
  92. <if test="remarks != null and remarks != ''">
  93. AND t.remarks = #{remarks}
  94. </if>
  95. <if test="opCreateTime != null">
  96. AND t.op_create_time = #{opCreateTime}
  97. </if>
  98. <if test="opCreateUserId != null and opCreateUserId != ''">
  99. AND t.op_create_user_id = #{opCreateUserId}
  100. </if>
  101. <if test="opUpdateTime != null">
  102. AND t.op_update_time = #{opUpdateTime}
  103. </if>
  104. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  105. AND t.op_update_user_id = #{opUpdateUserId}
  106. </if>
  107. <if test="opAppCode != null and opAppCode != ''">
  108. AND t.op_app_code = #{opAppCode}
  109. </if>
  110. <if test="opTimestamp != null">
  111. AND t.op_timestamp = #{opTimestamp}
  112. </if>
  113. <if test="opDbUser != null and opDbUser != ''">
  114. AND t.op_db_user = #{opDbUser}
  115. </if>
  116. <if test="owner != null and owner != ''">
  117. AND t.owner = #{owner}
  118. </if>
  119. </where>
  120. </sql>
  121. <!-- 根据主键查询表t_mst_staff的一行数据 -->
  122. <select id="selectById" resultMap="BaseResultMap">
  123. SELECT
  124. <include refid="Base_Column_List"/>
  125. ,g.grade_name gradeName
  126. FROM dkic_a.t_a_company t
  127. left join sys.t_grade g on t.grade_code = g.grade_code
  128. WHERE t.cp_id = #{cpId}
  129. </select>
  130. <insert id="insert">
  131. insert into dkic_a.t_a_company
  132. (cp_name,
  133. svc_code,
  134. grade_code,
  135. max_staff_num,
  136. cur_staff_num,
  137. owner,
  138. cp_manager,
  139. cp_phone,
  140. cp_size,
  141. shop_size,
  142. feedback)
  143. values (#{cpName},
  144. dkic_a.f_allot_service(#{gradeCode}) ,
  145. #{gradeCode} ,
  146. #{maxStaffNum},
  147. #{curStaffNum},
  148. #{owner}::uuid,
  149. #{cpManager},
  150. #{cpPhone},
  151. #{cpSize},
  152. #{shopSize},
  153. #{feedback}
  154. )
  155. </insert>
  156. <sql id="idsForeach">
  157. <!-- 根据主键cpId批量操作 -->
  158. WHERE cp_id in
  159. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  160. #{item}
  161. </foreach>
  162. </sql>
  163. <!-- 获取商户的地址服务 -->
  164. <select id="selectServiceAllot" resultType="String">
  165. SELECT dkic_a.f_allot_service(#{gradeCode})
  166. </select>
  167. <!-- 查询表t_a_company,(条件查询+分页)列表 -->
  168. <select id="selectByCond" resultMap="BaseResultMap">
  169. SELECT
  170. <include refid="Base_Column_List"/>
  171. FROM dkic_a.t_a_company t
  172. <include refid="Condition"/>
  173. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  174. limit #{end} offset #{start}
  175. </if>
  176. </select>
  177. <!-- 查询表t_a_company,(条件查询)个数 -->
  178. <select id="countByCond" resultType="Long">
  179. SELECT
  180. count(1)
  181. FROM dkic_a.t_a_company t
  182. <include refid="Condition"/>
  183. </select>
  184. <insert id="insertBatch">
  185. insert into dkic_a.t_a_company
  186. (
  187. <trim suffixOverrides=",">
  188. cp_code,
  189. cp_name,
  190. svc_code,
  191. opening_date,
  192. grade_code,
  193. end_date,
  194. max_staff_num,
  195. cur_staff_num,
  196. remarks,
  197. op_app_code,
  198. owner,
  199. </trim>
  200. )
  201. values
  202. <foreach collection="list" index="index" item="item" separator=",">
  203. (
  204. <trim suffixOverrides=",">
  205. #{item.cpCode},
  206. #{item.cpName},
  207. #{item.svcCode},
  208. #{item.openingDate},
  209. #{item.gradeCode},
  210. #{item.endDate},
  211. #{item.maxStaffNum},
  212. #{item.curStaffNum},
  213. #{item.remarks},
  214. #{item.opAppCode},
  215. #{item.owner}::uuid,
  216. </trim>
  217. )
  218. </foreach>
  219. </insert>
  220. </mapper>