MkDistHierDao.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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.kmall.admin.dao.mk.dist.MkDistHierDao">
  4. <resultMap type="com.kmall.admin.entity.mk.dist.MkDistHierEntity" id="mkDistHierMap">
  5. <result property="distHierId" column="dist_hier_id"/>
  6. <result property="distChnlId" column="dist_chnl_id"/>
  7. <result property="pdistId" column="pdist_id"/>
  8. <result property="distId" column="dist_id"/>
  9. <result property="distHierName" column="dist_hier_name"/>
  10. <result property="distHierNname" column="dist_hier_nname"/>
  11. <result property="hierLvl" column="hier_lvl"/>
  12. <result property="supplierId" column="supplier_id"/>
  13. <result property="sortOrder" column="sort_order"/>
  14. <result property="isValid" column="is_valid"/>
  15. <result property="note" column="note"/>
  16. <result property="createrSn" column="creater_sn"/>
  17. <result property="createTime" column="create_time"/>
  18. <result property="moderSn" column="moder_sn"/>
  19. <result property="modTime" column="mod_time"/>
  20. <result property="tstm" column="tstm"/>
  21. <result property="pdDistName" column="pdDistName"/>
  22. <result property="distName" column="distName"/>
  23. <result property="distFlag" column="distFlag"/>
  24. <result property="childSupplierName" column="childSupplierName"/>
  25. </resultMap>
  26. <select id="queryObject" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  27. select
  28. `dist_hier_id`,
  29. `dist_chnl_id`,
  30. `pdist_id`,
  31. `dist_id`,
  32. `dist_hier_name`,
  33. `dist_hier_nname`,
  34. `hier_lvl`,
  35. `supplier_id`,
  36. `sort_order`,
  37. `is_valid`,
  38. `note`,
  39. `creater_sn`,
  40. `create_time`,
  41. `moder_sn`,
  42. `mod_time`,
  43. `tstm`
  44. from mk_dist_hier
  45. where dist_hier_id = #{id}
  46. </select>
  47. <select id="queryObjectByName" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  48. select
  49. `dist_hier_id`,
  50. `dist_chnl_id`,
  51. `pdist_id`,
  52. `dist_id`,
  53. `dist_hier_name`,
  54. `dist_hier_nname`,
  55. `hier_lvl`,
  56. `supplier_id`,
  57. `sort_order`,
  58. `is_valid`,
  59. `note`,
  60. `creater_sn`,
  61. `create_time`,
  62. `moder_sn`,
  63. `mod_time`,
  64. `tstm`
  65. from mk_dist_hier
  66. where dist_hier_name = #{distHierName}
  67. </select>
  68. <select id="queryObjectByPdistIdAndChnlId" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  69. select
  70. h.`dist_hier_id`,
  71. h.`dist_chnl_id`,
  72. h.`pdist_id`,
  73. h.`dist_id`,
  74. h.`dist_hier_name`,
  75. h.`dist_hier_nname`,
  76. h.`hier_lvl`,
  77. h.`supplier_id`,
  78. h.`sort_order`,
  79. h.`is_valid`,
  80. h.`note`,
  81. h.`creater_sn`,
  82. h.`create_time`,
  83. h.`moder_sn`,
  84. h.`mod_time`,
  85. h.`tstm`,cc.dist_flag,d.dist_name
  86. from mk_dist_hier h
  87. left join mk_dist_chnl cc on h.dist_chnl_id = cc.dist_chnl_id
  88. left join mk_dist d on h.pdist_id = d.dist_id
  89. where 1=1
  90. <if test="pdistId != null and pdistId != ''">
  91. and h.pdist_id = #{pdistId}
  92. </if>
  93. <if test="distChnlId != null and distChnlId != ''">
  94. and h.dist_chnl_id = #{distChnlId}
  95. </if>
  96. order by h.mod_time desc
  97. </select>
  98. <select id="queryList" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  99. select
  100. h.`dist_hier_id`,
  101. h.`dist_chnl_id`,
  102. h.`pdist_id` 'parentId',
  103. h.`dist_id`,
  104. h.`dist_hier_name`,
  105. h.`dist_hier_nname`,
  106. h.`hier_lvl`,
  107. h.`supplier_id`,
  108. h.`sort_order`,
  109. h.`is_valid`,
  110. h.`note`,
  111. h.`creater_sn`,
  112. h.`create_time`,
  113. h.`moder_sn`,
  114. h.`mod_time`,
  115. h.`tstm`,d1.dist_name 'parentName',d2.dist_name 'name',dc.dist_flag 'distFlag',s.child_supplier_name 'childSupplierName'
  116. from mk_dist_hier h
  117. left join mk_dist_chnl dc on h.dist_chnl_id = dc.dist_chnl_id
  118. left join mk_dist d1 on h.pdist_id = d1.dist_id
  119. left join mk_dist d2 on h.dist_id = d2.dist_id
  120. left join mall_supplier s on h.supplier_id = s.id
  121. left join third_merchant_biz t on dc.third_merch_sn = t.third_merch_sn
  122. LEFT JOIN mall_store st ON d1.store_id = st.id
  123. LEFT JOIN mall_store st2 ON d2.store_id = st2.id
  124. WHERE 1=1
  125. <if test="distHierName != null and distHierName.trim() != ''">
  126. AND h.dist_hier_name LIKE concat('%',#{distHierName},'%')
  127. </if>
  128. <if test="pdistId != null and pdistId != ''">
  129. AND h.pdist_id = #{pdistId}
  130. </if>
  131. <if test="distId != null and distId != ''">
  132. AND h.dist_id = #{distId}
  133. </if>
  134. <if test="thirdMerchSn != null and thirdMerchSn != ''">
  135. AND dc.third_merch_sn = #{thirdMerchSn}
  136. </if>
  137. <if test="merchSn != null and merchSn != ''">
  138. AND t.merch_sn = #{merchSn}
  139. </if>
  140. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
  141. AND t.third_party_merch_code = #{thirdPartyMerchCode}
  142. </if>
  143. <if test="storeId != null and storeId != ''">
  144. AND st2.id = #{storeId}
  145. </if>
  146. <choose>
  147. <when test="sidx != null and sidx.trim() != ''">
  148. order by ${sidx} ${order}
  149. </when>
  150. <otherwise>
  151. order by h.dist_hier_id desc
  152. </otherwise>
  153. </choose>
  154. <if test="offset != null and limit != null">
  155. limit #{offset}, #{limit}
  156. </if>
  157. </select>
  158. <select id="queryTotal" resultType="int">
  159. select count(*) from mk_dist_hier h
  160. left join mk_dist_chnl dc on h.dist_chnl_id = dc.dist_chnl_id
  161. left join mk_dist d1 on h.pdist_id = d1.dist_id
  162. left join mk_dist d2 on h.dist_id = d2.dist_id
  163. left join mall_supplier s on h.supplier_id = s.id
  164. left join third_merchant_biz t on dc.third_merch_sn = t.third_merch_sn
  165. LEFT JOIN mall_store st ON d1.store_id = st.id
  166. LEFT JOIN mall_store st2 ON d2.store_id = st2.id
  167. WHERE 1=1
  168. <if test="distHierName != null and distHierName.trim() != ''">
  169. AND h.dist_hier_name LIKE concat('%',#{distHierName},'%')
  170. </if>
  171. <if test="pdistId != null">
  172. AND h.pdist_id = #{pdistId}
  173. </if>
  174. <if test="thirdMerchSn != null and thirdMerchSn != ''">
  175. AND dc.third_merch_sn = #{thirdMerchSn}
  176. </if>
  177. <if test="merchSn != null and merchSn != ''">
  178. AND t.merch_sn = #{merchSn}
  179. </if>
  180. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
  181. AND t.third_party_merch_code = #{thirdPartyMerchCode}
  182. </if>
  183. <if test="storeId != null and storeId != ''">
  184. AND st2.id = #{storeId}
  185. </if>
  186. </select>
  187. <select id="queryListByTree" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  188. SELECT
  189. h.`dist_id`,
  190. h.`pdist_id`,
  191. d2.dist_name NAME,
  192. d1.dist_name parentName,
  193. h.hier_lvl,
  194. h.dist_chnl_id
  195. FROM
  196. mk_dist_hier h
  197. LEFT JOIN mk_dist_chnl dc ON h.dist_chnl_id = dc.dist_chnl_id
  198. LEFT JOIN mk_dist d1 ON h.pdist_id = d1.dist_id
  199. LEFT JOIN mk_dist d2 ON h.dist_id = d2.dist_id
  200. WHERE
  201. 1 = 1
  202. <if test="pdistId != null and pdistId != ''">
  203. AND h.pdist_id = ( SELECT pdist_id FROM mk_dist_hier WHERE 1 = 1 and dist_id = #{pdistId})
  204. </if>
  205. <if test="distId != null and distId != ''">
  206. AND h.dist_id = #{distId}
  207. </if>
  208. <if test="hierLvl != null and hierLvl != ''">
  209. AND h.hier_lvl = #{hierLvl}
  210. </if>
  211. <choose>
  212. <when test="sidx != null and sidx.trim() != ''">
  213. order by ${sidx} ${order}
  214. </when>
  215. </choose>
  216. </select>
  217. <!--
  218. <select id="queryListByTree" resultType="com.kmall.admin.entity.mk.MkDistHierEntity">
  219. &lt;!&ndash;select * from (&ndash;&gt;
  220. select
  221. h.`dist_id`,
  222. h.`pdist_id`,
  223. d2.dist_name name,
  224. d1.dist_name parentName,
  225. h.hier_lvl
  226. from mk_dist_hier h
  227. left join mk_dist_chnl dc on h.dist_chnl_id = dc.dist_chnl_id
  228. left join mk_dist d1 on h.pdist_id = d1.dist_id
  229. left join mk_dist d2 on h.dist_id = d2.dist_id
  230. WHERE 1=1
  231. <if test="pdistId != null">
  232. AND h.pdist_id = #{pdistId}
  233. </if>
  234. &lt;!&ndash;UNION all&ndash;&gt;
  235. &lt;!&ndash;select d1.`dist_id` dist_id,&ndash;&gt;
  236. &lt;!&ndash;d1.is_valid pdist_id,&ndash;&gt;
  237. &lt;!&ndash;d1.dist_name parentName,&ndash;&gt;
  238. &lt;!&ndash;d1.dist_name name,&ndash;&gt;
  239. &lt;!&ndash;0 'hier_lvl' from mk_dist d1&ndash;&gt;
  240. &lt;!&ndash;WHERE 1=1&ndash;&gt;
  241. &lt;!&ndash;<if test="pdistId != null">&ndash;&gt;
  242. &lt;!&ndash;AND d1.dist_id = #{pdistId}&ndash;&gt;
  243. &lt;!&ndash;</if>&ndash;&gt;
  244. &lt;!&ndash;)s&ndash;&gt;
  245. <choose>
  246. <when test="sidx != null and sidx.trim() != ''">
  247. order by ${sidx} ${order}
  248. </when>
  249. </choose>
  250. </select>-->
  251. <select id="selectDistHierByChnlIdAndOneLvl" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  252. SELECT * FROM `mk_dist_hier` where 1=1 and dist_chnl_id = #{distChnlId} and hier_lvl = 1
  253. <if test="distHierId != null and distHierId != ''">
  254. and dist_hier_id != #{distHierId}
  255. </if>
  256. </select>
  257. <select id="selectDistHierByDistId" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  258. SELECT * FROM `mk_dist_hier` where 1=1 and dist_id = #{distId}
  259. </select>
  260. <select id="selectDistHierByDistChnlId" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  261. SELECT * FROM `mk_dist_hier` where 1=1 and dist_chnl_id = #{distChnlId}
  262. </select>
  263. <select id="queryListByPdistIdAndChnlIdAndDistId" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  264. SELECT h.*
  265. FROM mk_dist_hier h
  266. WHERE 1=1
  267. <if test="pdistId != null">
  268. AND h.pdist_id = #{pdistId}
  269. </if>
  270. <if test="distChnlId != null">
  271. AND h.dist_chnl_id = #{distChnlId}
  272. </if>
  273. <if test="distId != null">
  274. AND h.dist_id = #{distId}
  275. </if>
  276. </select>
  277. <select id="queryObjectByDistIdAndPdistId" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  278. SELECT h.*
  279. FROM mk_dist_hier h
  280. WHERE 1=1
  281. <if test="pdistId != null">
  282. AND h.pdist_id = #{pdistId}
  283. </if>
  284. <if test="distId != null">
  285. AND h.dist_id = #{distId}
  286. </if>
  287. <if test="distHierId != null">
  288. AND h.dist_hier_id != #{distHierId}
  289. </if>
  290. </select>
  291. <select id="queryObjectByHierMap" resultType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  292. select
  293. h.`dist_hier_id`,
  294. h.`dist_chnl_id`,
  295. h.`pdist_id`,
  296. h.`dist_id`,
  297. h.`dist_hier_name`,
  298. h.`dist_hier_nname`,
  299. h.`hier_lvl`,
  300. h.`supplier_id`,
  301. h.`sort_order`,
  302. h.`is_valid`,
  303. h.`note`,
  304. h.`creater_sn`,
  305. h.`create_time`,
  306. h.`moder_sn`,
  307. h.`mod_time`,
  308. h.`tstm`,cc.dist_flag,d.dist_name
  309. from mk_dist_hier h
  310. left join mk_dist_chnl cc on h.dist_chnl_id = cc.dist_chnl_id
  311. left join mk_dist d on h.pdist_id = d.dist_id
  312. where 1=1
  313. <if test="pdistId != null and pdistId != ''">
  314. and h.pdist_id = #{pdistId}
  315. </if>
  316. <if test="distId != null and distId != ''">
  317. and h.dist_id = #{distId}
  318. </if>
  319. <if test="distChnlId != null and distChnlId != ''">
  320. and h.dist_chnl_id = #{distChnlId}
  321. </if>
  322. <if test="hierLvl != null and hierLvl != ''">
  323. and h.hier_lvl = #{hierLvl}
  324. </if>
  325. </select>
  326. <select id="querySysConfigByKey" resultType="map">
  327. select s.value from sys_config s where s.key = #{key}
  328. </select>
  329. <insert id="save" parameterType="com.kmall.admin.entity.mk.dist.MkDistHierEntity" useGeneratedKeys="true" keyProperty="distHierId">
  330. insert into mk_dist_hier(
  331. `dist_chnl_id`,
  332. `pdist_id`,
  333. `dist_id`,
  334. `dist_hier_name`,
  335. `dist_hier_nname`,
  336. `hier_lvl`,
  337. `supplier_id`,
  338. `sort_order`,
  339. `is_valid`,
  340. `note`,
  341. `creater_sn`,
  342. `create_time`,
  343. `moder_sn`,
  344. `mod_time`,
  345. `tstm`)
  346. values(
  347. #{distChnlId},
  348. #{pdistId},
  349. #{distId},
  350. #{distHierName},
  351. #{distHierNname},
  352. #{hierLvl},
  353. #{supplierId},
  354. #{sortOrder},
  355. #{isValid},
  356. #{note},
  357. #{createrSn},
  358. #{createTime},
  359. #{moderSn},
  360. #{modTime},
  361. #{tstm})
  362. </insert>
  363. <update id="update" parameterType="com.kmall.admin.entity.mk.dist.MkDistHierEntity">
  364. update mk_dist_hier
  365. <set>
  366. <if test="distChnlId != null">`dist_chnl_id` = #{distChnlId}, </if>
  367. <if test="pdistId != null">`pdist_id` = #{pdistId}, </if>
  368. <if test="distId != null">`dist_id` = #{distId}, </if>
  369. <if test="distHierName != null">`dist_hier_name` = #{distHierName}, </if>
  370. <if test="distHierNname != null">`dist_hier_nname` = #{distHierNname}, </if>
  371. <if test="hierLvl != null">`hier_lvl` = #{hierLvl}, </if>
  372. <if test="supplierId != null">`supplier_id` = #{supplierId}, </if>
  373. <if test="sortOrder != null">`sort_order` = #{sortOrder}, </if>
  374. <if test="isValid != null">`is_valid` = #{isValid}, </if>
  375. <if test="note != null">`note` = #{note}, </if>
  376. <if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
  377. <if test="createTime != null">`create_time` = #{createTime}, </if>
  378. <if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
  379. <if test="modTime != null">`mod_time` = #{modTime}, </if>
  380. <if test="tstm != null">`tstm` = #{tstm}</if>
  381. </set>
  382. where dist_hier_id = #{distHierId}
  383. </update>
  384. <delete id="delete">
  385. delete from mk_dist_hier where dist_hier_id = #{value}
  386. </delete>
  387. <delete id="deleteBatch">
  388. delete from mk_dist_hier where dist_hier_id in
  389. <foreach item="distHierId" collection="array" open="(" separator="," close=")">
  390. #{distHierId}
  391. </foreach>
  392. </delete>
  393. </mapper>