CompanyMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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.mdm.mapper.mst.CompanyMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. cp_id, cp_code, cp_name, svc_code, opening_date, grade_code, end_date, max_staff_num, cur_staff_num, flg_valid, remarks, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user, owner, cp_manager, cp_phone, cp_size, shop_size, feedback,cp_status
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.Company">
  11. <id column="cp_id" property="cpId"/>
  12. <result column="cp_code" property="cpCode"/>
  13. <result column="cp_name" property="cpName"/>
  14. <result column="svc_code" property="svcCode"/>
  15. <result column="opening_date" property="openingDate" typeHandler="TimestampTypeHandler"/>
  16. <result column="grade_code" property="gradeCode"/>
  17. <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
  18. <result column="max_staff_num" property="maxStaffNum"/>
  19. <result column="cur_staff_num" property="curStaffNum"/>
  20. <result column="flg_valid" property="flgValid"/>
  21. <result column="remarks" property="remarks"/>
  22. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  23. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  24. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  25. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  26. <result column="op_app_code" property="opAppCode"/>
  27. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  28. <result column="op_db_user" property="opDbUser"/>
  29. <result column="owner" property="owner" typeHandler="UuidTypeHandler"/>
  30. <result column="cp_manager" property="cpManager"/>
  31. <result column="cp_phone" property="cpPhone"/>
  32. <result column="cp_size" property="cpSize"/>
  33. <result column="shop_size" property="shopSize"/>
  34. <result column="feedback" property="feedback"/>
  35. <result column="cpStatus" property="cpStatus"/>
  36. </resultMap>
  37. <!-- 通用条件列 -->
  38. <sql id="Condition">
  39. <where>
  40. <if test="cpCode != null and cpCode != ''">
  41. AND cp_code = #{cpCode}
  42. </if>
  43. <if test="cpName != null and cpName != ''">
  44. AND cp_name = #{cpName}
  45. </if>
  46. <if test="svcCode != null and svcCode != ''">
  47. AND svc_code = #{svcCode}
  48. </if>
  49. <if test="openingDate != null">
  50. AND opening_date = #{openingDate}
  51. </if>
  52. <if test="gradeCode != null and gradeCode != ''">
  53. AND grade_code = #{gradeCode}
  54. </if>
  55. <if test="endDate != null">
  56. AND end_date = #{endDate}
  57. </if>
  58. <if test="maxStaffNum != null">
  59. AND max_staff_num = #{maxStaffNum}
  60. </if>
  61. <if test="curStaffNum != null">
  62. AND cur_staff_num = #{curStaffNum}
  63. </if>
  64. <if test="flgValid != null">
  65. AND flg_valid = #{flgValid}
  66. </if>
  67. <if test="remarks != null and remarks != ''">
  68. AND remarks = #{remarks}
  69. </if>
  70. <if test="opCreateTime != null">
  71. AND op_create_time = #{opCreateTime}
  72. </if>
  73. <if test="opCreateUserId != null and opCreateUserId != ''">
  74. AND op_create_user_id = #{opCreateUserId}
  75. </if>
  76. <if test="opUpdateTime != null">
  77. AND op_update_time = #{opUpdateTime}
  78. </if>
  79. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  80. AND op_update_user_id = #{opUpdateUserId}
  81. </if>
  82. <if test="opAppCode != null and opAppCode != ''">
  83. AND op_app_code = #{opAppCode}
  84. </if>
  85. <if test="opTimestamp != null">
  86. AND op_timestamp = #{opTimestamp}
  87. </if>
  88. <if test="opDbUser != null and opDbUser != ''">
  89. AND op_db_user = #{opDbUser}
  90. </if>
  91. <if test="owner != null and owner != ''">
  92. AND owner = #{owner}
  93. </if>
  94. <if test="cpManager != null and cpManager != ''">
  95. AND cp_manager = #{cpManager}
  96. </if>
  97. <if test="cpPhone != null and cpPhone != ''">
  98. AND cp_phone = #{cpPhone}
  99. </if>
  100. <if test="cpSize != null and cpSize != ''">
  101. AND cp_size = #{cpSize}
  102. </if>
  103. <if test="shopSize != null and shopSize != ''">
  104. AND shop_size = #{shopSize}
  105. </if>
  106. <if test="feedback != null and feedback != ''">
  107. AND feedback = #{feedback}
  108. </if>
  109. </where>
  110. </sql>
  111. <sql id="Base_Column_List_list">
  112. tac.cp_id,
  113. tac.cp_code,
  114. tac.cp_name,
  115. tac.svc_code,
  116. tac.opening_date,
  117. tac.grade_code,
  118. tac.end_date,
  119. tac.max_staff_num,
  120. tac.cur_staff_num,
  121. tac.flg_valid,
  122. tac.remarks,
  123. tac.op_create_time,
  124. tac.op_create_user_id,
  125. tac.op_update_time,
  126. tac.op_update_user_id,
  127. tac.op_app_code,
  128. tac.op_timestamp,
  129. tac.op_db_user,
  130. tac.owner,
  131. tac.cp_manager,
  132. tac.cp_phone,
  133. tac.cp_size,
  134. tac.shop_size,
  135. tac.feedback,
  136. tac.cp_status,
  137. tac.license
  138. </sql>
  139. <resultMap id="BaseResultMap_list" type="com.dk.mdm.model.response.mst.CompanyResponse">
  140. <id column="cp_id" property="cpId"/>
  141. <result column="cp_code" property="cpCode"/>
  142. <result column="cp_name" property="cpName"/>
  143. <result column="svc_code" property="svcCode"/>
  144. <result column="opening_date" property="openingDate" typeHandler="TimestampTypeHandler"/>
  145. <result column="grade_code" property="gradeCode"/>
  146. <result column="end_date" property="endDate" typeHandler="TimestampTypeHandler"/>
  147. <result column="max_staff_num" property="maxStaffNum"/>
  148. <result column="cur_staff_num" property="curStaffNum"/>
  149. <result column="flg_valid" property="flgValid"/>
  150. <result column="remarks" property="remarks"/>
  151. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  152. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  153. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  154. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  155. <result column="op_app_code" property="opAppCode"/>
  156. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  157. <result column="op_db_user" property="opDbUser"/>
  158. <result column="owner" property="owner" typeHandler="UuidTypeHandler"/>
  159. <result column="cp_manager" property="cpManager"/>
  160. <result column="cp_phone" property="cpPhone"/>
  161. <result column="cp_size" property="cpSize"/>
  162. <result column="shop_size" property="shopSize"/>
  163. <result column="feedback" property="feedback"/>
  164. <result column="cp_status" property="cpStatus"/>
  165. <result column="license" property="license"/>
  166. </resultMap>
  167. <sql id="Condition_list">
  168. <where>
  169. <if test="cpId != null and cpId != ''">
  170. AND tac.cp_id = #{cpId}
  171. </if>
  172. <if test="cpCode != null and cpCode != ''">
  173. AND tac.cp_code = #{cpCode}
  174. </if>
  175. <if test="cpName != null and cpName != ''">
  176. AND tac.cp_name LIKE concat('%',my_ex.likequery(#{cpName}),'%')
  177. </if>
  178. <if test="svcCode != null and svcCode != ''">
  179. AND tac.svc_code = #{svcCode}
  180. </if>
  181. <if test="openingDate != null">
  182. AND tac.opening_date = #{openingDate}
  183. </if>
  184. <if test="gradeCode != null and gradeCode != ''">
  185. AND tac.grade_code = #{gradeCode}
  186. </if>
  187. <if test="endDate != null">
  188. AND tac.end_date = #{endDate}
  189. </if>
  190. <if test="maxStaffNum != null">
  191. AND tac.max_staff_num = #{maxStaffNum}
  192. </if>
  193. <if test="curStaffNum != null">
  194. AND tac.cur_staff_num = #{curStaffNum}
  195. </if>
  196. <if test="flgValid != null">
  197. AND tac.flg_valid = #{flgValid}
  198. </if>
  199. <if test="remarks != null and remarks != ''">
  200. AND tac.remarks = #{remarks}
  201. </if>
  202. <if test="opCreateTime != null">
  203. AND tac.op_create_time = #{opCreateTime}
  204. </if>
  205. <if test="opCreateUserId != null and opCreateUserId != ''">
  206. AND tac.op_create_user_id = #{opCreateUserId}
  207. </if>
  208. <if test="opUpdateTime != null">
  209. AND tac.op_update_time = #{opUpdateTime}
  210. </if>
  211. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  212. AND tac.op_update_user_id = #{opUpdateUserId}
  213. </if>
  214. <if test="opAppCode != null and opAppCode != ''">
  215. AND tac.op_app_code = #{opAppCode}
  216. </if>
  217. <if test="opTimestamp != null">
  218. AND tac.op_timestamp = #{opTimestamp}
  219. </if>
  220. <if test="opDbUser != null and opDbUser != ''">
  221. AND tac.op_db_user = #{opDbUser}
  222. </if>
  223. <if test="owner != null and owner != ''">
  224. AND tac.owner = #{owner}
  225. </if>
  226. <if test="cpManager != null and cpManager != ''">
  227. AND tac.cp_manager = #{cpManager}
  228. </if>
  229. <if test="cpPhone != null and cpPhone != ''">
  230. AND tac.cp_phone LIKE concat('%',my_ex.likequery(#{cpPhone}),'%')
  231. </if>
  232. <if test="cpSize != null and cpSize != ''">
  233. AND tac.cp_size = #{cpSize}
  234. </if>
  235. <if test="shopSize != null and shopSize != ''">
  236. AND tac.shop_size = #{shopSize}
  237. </if>
  238. <if test="feedback != null and feedback != ''">
  239. AND tac.feedback = #{feedback}
  240. </if>
  241. <if test="openingDateStart != null and openingDateEnd != null">
  242. AND tac.opening_date &gt;= #{openingDateStart}::timestamp with time zone
  243. AND tac.opening_date &lt; #{openingDateEnd}::timestamp with time zone + interval '1 day'
  244. </if>
  245. <if test="endDateStart != null and endDateEnd != null">
  246. AND tac.end_date &gt;= #{endDateStart}::timestamp with time zone
  247. AND tac.end_date &lt; #{endDateEnd}::timestamp with time zone + interval '1 day'
  248. </if>
  249. </where>
  250. </sql>
  251. <sql id="idsForeach">
  252. <!-- 根据主键cpId批量操作 -->
  253. WHERE cp_id in
  254. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  255. #{item}
  256. </foreach>
  257. </sql>
  258. <!-- 查询表dkic_a.t_a_company,(条件查询+分页)列表 -->
  259. <select id="selectByCond" resultMap="BaseResultMap_list">
  260. SELECT
  261. <include refid="Base_Column_List_list"/>
  262. ,tss.svc_ip
  263. ,tss.svc_port
  264. ,case when (select count(1) from dkic_a.t_mst_receipt tmr where tmr.receipt_status = '发票状态-申请' and tmr.cp_id = tac.cp_id) > 0
  265. then TRUE else false END as "invoicingFlag"
  266. FROM dkic_a.t_a_company tac
  267. left join dkic_a.t_s_service tss
  268. on tac.svc_code = tss.svc_code
  269. <include refid="Condition_list"/>
  270. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  271. limit #{end} offset #{start}
  272. </if>
  273. </select>
  274. <!-- 查询表dkic_a.t_a_company,(条件查询)个数 -->
  275. <select id="countByCond" resultType="Long">
  276. SELECT
  277. count(1)
  278. FROM dkic_a.t_a_company tac
  279. <include refid="Condition_list"/>
  280. </select>
  281. <!-- 根据主键锁定表dkic_a.t_a_company的一行数据 -->
  282. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  283. SELECT
  284. <include refid="Base_Column_List"/>
  285. FROM dkic_a.t_a_company
  286. WHERE cp_id = #{cpId}
  287. for update
  288. </select>
  289. <!-- 根据主键锁定表dkic_a.t_a_company的多行数据 -->
  290. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  291. SELECT
  292. <include refid="Base_Column_List"/>
  293. FROM dkic_a.t_a_company
  294. <include refid="idsForeach"/>
  295. for update
  296. </select>
  297. <insert id="insertBatch">
  298. insert into dkic_a.t_a_company
  299. (
  300. <trim suffixOverrides=",">
  301. cp_code,
  302. cp_name,
  303. svc_code,
  304. opening_date,
  305. grade_code,
  306. end_date,
  307. max_staff_num,
  308. cur_staff_num,
  309. remarks,
  310. op_app_code,
  311. owner,
  312. cp_manager,
  313. cp_phone,
  314. cp_size,
  315. shop_size,
  316. feedback,
  317. </trim>
  318. )
  319. values
  320. <foreach collection="list" index="index" item="item" separator=",">
  321. (
  322. <trim suffixOverrides=",">
  323. #{item.cpCode},
  324. #{item.cpName},
  325. #{item.svcCode},
  326. #{item.openingDate},
  327. #{item.gradeCode},
  328. #{item.endDate},
  329. #{item.maxStaffNum},
  330. #{item.curStaffNum},
  331. #{item.remarks},
  332. #{item.opAppCode},
  333. #{item.owner}::uuid,
  334. #{item.cpManager},
  335. #{item.cpPhone},
  336. #{item.cpSize},
  337. #{item.shopSize},
  338. #{item.feedback},
  339. </trim>
  340. )
  341. </foreach>
  342. </insert>
  343. <!-- 获取商户的地址服务 -->
  344. <select id="selectServiceAllot" resultType="String">
  345. SELECT dkic_a.f_allot_service(#{gradeCode})
  346. </select>
  347. <!-- 获取商户的IP地址和端口 -->
  348. <select id="selectIPAndPort" resultType="java.util.Map">
  349. SELECT ts.svc_ip ,
  350. ts.svc_port
  351. from dkic_a.t_s_service ts
  352. where ts.svc_code = #{svcCode}
  353. </select>
  354. <!--更新公司所有者-->
  355. <update id="updateOwners">
  356. update dkic_a.t_a_company set owner = #{userId}::uuid
  357. where cp_Id = #{cpId}
  358. </update>
  359. <!--责任人转让-->
  360. <update id="updateCpManager">
  361. update dkic_a.t_a_company
  362. set owner = #{userId}::uuid
  363. ,cp_manager = #{staffName}
  364. ,cp_phone = #{staffPhone}
  365. where cp_Id = #{cpId}
  366. </update>
  367. </mapper>