StoreItemUnit.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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.oqpo.api.mapper.stinfo.StoreItemUnitMapper">
  4. <select id="selectStoreItemUnitGridList" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  5. select /* selectStoreItemUnitGridList */
  6. iunit.brand_id, fn_brand_nm(iunit.brand_id) as brand_nm, iunit.store_id, fn_store_nm(iunit.brand_id, iunit.store_id) as store_nm,
  7. date_format(iunit.cont_stt_dt,'%Y.%m.%d') as cont_stt_dt, date_format(iunit.cont_end_dt,'%Y.%m.%d') as cont_end_dt,
  8. date_format(iunit.sys_reg_dttm,'%Y.%m.%d') as sys_reg_dttm, iunit.item_cnt
  9. from (
  10. select brand_id, store_id, cont_stt_dt, cont_end_dt, min(sys_reg_dttm) as sys_reg_dttm, count(*) as item_cnt
  11. from store_item_unit_info
  12. where brand_id = #{sBrandId}
  13. <if test="sStoreId != null and sStoreId != ''">
  14. and store_id = #{sStoreId}
  15. </if>
  16. <if test="sStoreNm != null and sStoreNm != ''">
  17. and store_id in (select a.store_id from store_base_info a where a.brand_id = #{sBrandId} and a.store_nm like concat('%', #{sStoreNm}, '%'))
  18. </if>
  19. and unit_target_cd = 'Y'
  20. group by brand_id, store_id, cont_stt_dt, cont_end_dt
  21. ) iunit
  22. <choose>
  23. <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
  24. <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
  25. <if test="gridRequest.sord == 'asc'.toString()">
  26. order by store_nm asc
  27. </if>
  28. <if test="gridRequest.sord == 'desc'.toString()">
  29. order by store_nm desc
  30. </if>
  31. </if>
  32. </when>
  33. <otherwise>
  34. order by store_nm asc
  35. </otherwise>
  36. </choose>
  37. <if test="gridRequest.pagingYn == true">
  38. limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
  39. </if>
  40. </select>
  41. <select id="selectStoreItemUnitGridCnt" resultType="int">
  42. select /*selectStoreItemUnitGridCnt*/
  43. count(*)
  44. from (
  45. select distinct brand_id, store_id, cont_stt_dt, cont_end_dt
  46. from store_item_unit_info
  47. where brand_id = #{sBrandId}
  48. <if test="sStoreId != null and sStoreId != ''">
  49. and store_id = #{sStoreId}
  50. </if>
  51. <if test="sStoreNm != null and sStoreNm != ''">
  52. and store_id in (select a.store_id from store_base_info a where a.brand_id = #{sBrandId} and a.store_nm like concat('%', #{sStoreNm}, '%'))
  53. </if>
  54. and unit_target_cd = 'Y'
  55. ) iunit
  56. </select>
  57. <!--
  58. <select id="selectSstoreItemUnitGridList" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  59. select /* selectStoreItemUnitGridList */
  60. iunit.brand_id, fn_brand_nm(iunit.brand_id) as brand_nm, iunit.store_id, fn_store_nm(iunit.brand_id, iunit.store_id) as store_nm,
  61. date_format(iunit.cont_stt_dt,'%Y.%m.%d') as cont_stt_dt, date_format(iunit.cont_end_dt,'%Y.%m.%d') as cont_end_dt,
  62. date_format(iunit.sys_reg_dttm,'%Y.%m.%d') as sys_reg_dttm, iunit.item_cnt
  63. from (
  64. select brand_id, store_id, cont_stt_dt, cont_end_dt, min(sys_reg_dttm) as sys_reg_dttm, count(*) as item_cnt
  65. from store_item_unit_info
  66. where brand_id = #{sBrandId}
  67. and store_id = #{sStoreId}
  68. and unit_target_cd = 'Y'
  69. group by brand_id, store_id, cont_stt_dt, cont_end_dt
  70. ) iunit
  71. <choose>
  72. <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
  73. <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
  74. <if test="gridRequest.sord == 'asc'.toString()">
  75. order by store_nm asc
  76. </if>
  77. <if test="gridRequest.sord == 'desc'.toString()">
  78. order by store_nm desc
  79. </if>
  80. </if>
  81. </when>
  82. <otherwise>
  83. order by store_nm asc
  84. </otherwise>
  85. </choose>
  86. <if test="gridRequest.pagingYn == true">
  87. limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
  88. </if>
  89. </select>
  90. <select id="selectSstoreItemUnitGridCnt" resultType="int">
  91. select /*selectStoreItemUnitGridCnt*/
  92. count(*)
  93. from (
  94. select distinct brand_id, store_id, cont_stt_dt, cont_end_dt
  95. from store_item_unit_info
  96. where brand_id = #{sBrandId}
  97. and store_id = #{sStoreId}
  98. and unit_target_cd = 'Y'
  99. ) iunit
  100. </select>
  101. -->
  102. <select id="selectStoreItemUnitInfo" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  103. select /*selectStoreItemUnitInfo*/
  104. case when unit.store_unit_unq_no is null then 'C' else 'R' end view_cd,
  105. unit.store_unit_unq_no, item.brand_id, item.item_id, item.item_nm,
  106. case when unit.cont_stt_dt is null or unit.cont_stt_dt = '' then date_format(#{contSttDt},'%Y.%m.%d') else date_format(unit.cont_stt_dt,'%Y.%m.%d') end as cont_stt_dt,
  107. case when unit.cont_end_dt is null or unit.cont_end_dt = '' then date_format(#{contEndDt},'%Y.%m.%d') else date_format(unit.cont_end_dt,'%Y.%m.%d') end as cont_end_dt,
  108. case when unit.unit is null or unit.unit = '' or store.loan_dvsn = 'LD03' then item.unit else unit.unit end as unit ,
  109. case when unit.unit is null or unit.unit = '' or store.loan_dvsn = 'LD03' then fn_code_nm('DSTRBT_COST_UNIT',item.unit) else fn_code_nm('DSTRBT_COST_UNIT',unit.unit) end as unit_nm ,
  110. case when nvl(unit.stdd_qty,0) = 0 or store.loan_dvsn = 'LD03' then item.store_sale_stdd_qty else unit.stdd_qty end as stdd_qty ,
  111. case when unit.curr is null or unit.curr = '' or store.loan_dvsn = 'LD03' then item.curr else unit.curr end as curr,
  112. case when unit.curr is null or unit.curr = '' or store.loan_dvsn = 'LD03' then fn_code_nm('CURR',item.curr) else fn_code_nm('CURR',unit.curr) end as curr_nm,
  113. case when unit.unit_amt is null or unit.unit_amt = 0 or store.loan_dvsn = 'LD03' then item.store_sale_unit_amt else unit.unit_amt end as unit_amt,
  114. case when unit.unit_target_cd is null or unit.unit_target_cd = '' or store.loan_dvsn = 'LD03' then 'Y' else unit.unit_target_cd end as unit_target_cd,
  115. case when unit.unit_target_cd is null or unit.unit_target_cd = '' or store.loan_dvsn = 'LD03' then fn_code_nm('DSTRBT_COST_UNIT','Y') else fn_code_nm('DSTRBT_COST_UNIT',unit.unit_target_cd) end as unit_target_nm,
  116. nvl(item.unit_amt,0) as spply_unit_amt
  117. ,item.brand_unit_unq_no,item.spply_id,fn_spply_nm(item.spply_id) as spply_nm
  118. from brand_item_unit_info item
  119. left outer join store_item_unit_info unit on item.brand_unit_unq_no = unit.brand_unit_unq_no and item.brand_id = unit.brand_id and item.item_id = unit.item_id and unit.store_id = #{storeId}
  120. and unit.cont_stt_dt = #{contSttDt} and unit.cont_end_dt = #{contEndDt}
  121. left outer join store_base_info store on unit.store_id = store.store_id and store.store_id = #{storeId}
  122. where item.brand_id = #{brandId}
  123. order by view_cd, item.item_id, item.unit_amt
  124. </select>
  125. <select id="selectStoreItemUnitContDateInfo" resultType="String">
  126. select /* selectStoreItemUnitContDateInfo */
  127. nvl(max(cont_end_dt),'') as cont_end_dt
  128. from store_item_unit_info
  129. where brand_id = #{brandId}
  130. and store_id = #{storeId}
  131. and cont_end_dt between #{contSttDt} and #{contEndDt}
  132. </select>
  133. <select id="selectStoreItemUnitExistYn" resultType="String">
  134. select /* selectStoreItemUnitContDateInfo */
  135. case when count(*) > 0 then 'Y' else 'N' END
  136. from store_item_unit_info
  137. where brand_id = #{brandId}
  138. and store_id = #{storeId}
  139. and cont_stt_dt = #{contSttDt}
  140. and cont_end_dt = #{contEndDt}
  141. </select>
  142. <select id="selectStoreItemUnitContDtInfo" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  143. select distinct nvl(max(cont_stt_dt) ,'') as cont_stt_dt, nvl(max(cont_end_dt) ,'') as cont_end_dt
  144. from store_item_unit_info
  145. where brand_id = #{brandId}
  146. and store_id = #{storeId}
  147. </select>
  148. <update id="updateStoreItemUnitContEnd" >
  149. update /* updateStoreItemUnitContEnd */
  150. store_item_unit_info
  151. set cont_end_dt = date_format(DATE_SUB(date_format(#{contSttDt},'%Y%m%d'), INTERVAL 1 DAY),'%Y%m%d')
  152. where brand_id = #{brandId}
  153. and store_id = #{storeId}
  154. and cont_end_dt = #{contEndDt}
  155. </update>
  156. <insert id="insertStoreItemUnitInfo" >
  157. insert into /** insertStoreItemUnitInfo */
  158. store_item_unit_info
  159. (store_unit_unq_no, cont_stt_dt, cont_end_dt, unit,
  160. curr, unit_amt, store_id, brand_id, short_cont_file_no,
  161. unit_target_cd, item_id, stdd_qty, brand_unit_unq_no,
  162. sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
  163. values
  164. <foreach collection="gridUpdateData" item="item" separator=",">
  165. ( fn_get_dealno(34,''), #{item.contSttDt}, #{item.contEndDt}, #{item.unit},
  166. #{item.curr}, #{item.unitAmt}, #{storeId}, #{brandId}, #{item.shortContFileNo},
  167. #{item.unitTargetCd}, #{item.itemId}, #{item.stddQty}, #{item.brandUnitUnqNo},
  168. NOW(), #{userId}, NOW(), #{userId})
  169. </foreach>
  170. </insert>
  171. <update id="updateStoreItemUnitInfo">
  172. <foreach collection="gridUpdateData" item="item" separator=";">
  173. UPDATE store_item_unit_info /* storeitemUnit.updateStoreItemUnitInfo */
  174. SET sys_chg_dttm = now()
  175. , sys_chg_id = #{userId}
  176. , cont_end_dt = #{item.contEndDt}
  177. , unit = #{item.unit}
  178. , curr = #{item.curr}
  179. , unit_amt = #{item.unitAmt}
  180. , unit_target_cd = #{item.unitTargetCd}
  181. WHERE store_unit_unq_no = #{item.storeUnitUnqNo}
  182. </foreach>
  183. </update>
  184. <insert id="insertMergStoreItemUnitInfo" >
  185. insert into /** Merge insertMergStoreItemUnitInfo */
  186. store_item_unit_info
  187. (store_unit_unq_no, cont_stt_dt, cont_end_dt, unit,
  188. curr, unit_amt, store_id, brand_id, short_cont_file_no,
  189. unit_target_cd, item_id, brand_unit_unq_no,
  190. sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
  191. values
  192. <foreach collection="gridUpdateData" item="item" separator=",">
  193. ( fn_get_dealno(34,''), #{item.contSttDt}, #{item.contEndDt}, #{item.unit},
  194. #{item.curr}, #{item.unitAmt}, #{storeId}, #{brandId}, #{item.shortContFileNo},
  195. #{item.unitTargetCd}, #{item.itemId}, #{item.brandUnitUnqNo},
  196. NOW(), #{userId}, NOW(), #{userId})
  197. </foreach>
  198. on duplicate key
  199. update
  200. sys_chg_dttm = now()
  201. , sys_chg_id = #{userId}
  202. , cont_stt_dt = VALUES(cont_stt_dt)
  203. , cont_end_dt = VALUES(cont_end_dt)
  204. , unit = VALUES(unit)
  205. , curr = VALUES(curr)
  206. , unit_amt = VALUES(unit_amt)
  207. , unit_target_cd = VALUES(unit_target_cd)
  208. , stdd_qty = VALUES(stdd_qty)
  209. </insert>
  210. <select id="selectStoreNewItemUnitInfo" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  211. select /*selectStoreNewItemUnitInfo*/
  212. 'C' view_cd,
  213. '' as store_unit_unq_no, item.brand_id, item.item_id, item.item_nm,
  214. '' as cont_stt_dt, '' as cont_end_dt,
  215. item.unit, fn_code_nm('DSTRBT_COST_UNIT',item.unit) as unit_nm,
  216. item.stdd_qty, item.CURR, fn_code_nm('CURR',item.curr) as curr_nm,
  217. item.store_sale_unit_amt as usit_amt, 'Y' as unit_target_cd,
  218. fn_code_nm('DSTRBT_COST_UNIT','Y') as unit_target_nm,
  219. item.unit_amt as spply_unit_amt,
  220. item.brand_unit_unq_no, item.store_sale_unit_amt as unit_amt,
  221. spply_id, fn_spply_nm(spply_id) as spply_nm
  222. from brand_item_unit_info item
  223. where item.brand_id = #{brandId}
  224. order by item.item_id, item.unit_amt
  225. </select>
  226. <select id="selectStoreItemUnitEndDtInfo" resultType="String">
  227. select max(cont_end_dt)
  228. from store_item_unit_info
  229. where brand_id = #{brandId}
  230. and store_id = #{storeId}
  231. and cont_stt_dt = #{contSttDt}
  232. </select>
  233. <update id="updateStoreItemUnitChgContEnd" >
  234. update /* updateStoreItemUnitChgContEnd */
  235. store_item_unit_info
  236. set cont_end_dt = #{contEndDt}
  237. where brand_id = #{brandId}
  238. and store_id = #{storeId}
  239. and cont_stt_dt = #{contSttDt}
  240. </update>
  241. </mapper>