StoreItemUnit.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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="sStoreNm != null and sStoreNm != ''">
  14. and store_nm = concat('%',#{sStoreNm},'%')
  15. </if>
  16. and unit_target_cd = 'Y'
  17. group by brand_id, store_id, cont_stt_dt, cont_end_dt
  18. ) iunit
  19. <choose>
  20. <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
  21. <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
  22. <if test="gridRequest.sord == 'asc'.toString()">
  23. order by store_nm asc
  24. </if>
  25. <if test="gridRequest.sord == 'desc'.toString()">
  26. order by store_nm desc
  27. </if>
  28. </if>
  29. </when>
  30. <otherwise>
  31. order by store_nm asc
  32. </otherwise>
  33. </choose>
  34. <if test="gridRequest.pagingYn == true">
  35. limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
  36. </if>
  37. </select>
  38. <select id="selectStoreItemUnitGridCnt" resultType="int">
  39. select /*selectStoreItemUnitGridCnt*/
  40. count(*)
  41. from (
  42. select distinct brand_id, store_id, cont_stt_dt, cont_end_dt
  43. from store_item_unit_info
  44. where brand_id = #{sBrandId}
  45. <if test="sStoreNm != null and sStoreNm != ''">
  46. and store_nm = concat('%',#{sStoreNm},'%')
  47. </if>
  48. and unit_target_cd = 'Y'
  49. ) iunit
  50. </select>
  51. <select id="selectStoreItemUnitInfo" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
  52. select /*selectStoreItemUnitInfo*/
  53. unit.store_unit_unq_no, item.brand_id, item.item_id, item.item_nm,
  54. case when unit.cont_stt_dt is null or unit.cont_stt_dt = '' then #{contSttDt} else date_format(unit.cont_stt_dt,'%Y.%m.%d') end as cont_stt_dt,
  55. case when unit.cont_end_dt is null or unit.cont_end_dt = '' then #{contEndDt} else date_format(unit.cont_end_dt,'%Y.%m.%d') end as cont_end_dt,
  56. case when unit.unit is null or unit.unit = '' then item.unit else unit.unit end as unit ,
  57. case when unit.unit is null or unit.unit = '' then fn_code_nm('DSTRBT_COST_UNIT',item.unit) else fn_code_nm('DSTRBT_COST_UNIT',unit.unit) end as unit_nm ,
  58. case when nvl(unit.stdd_qty,0) = 0 then item.store_sale_stdd_qty else unit.stdd_qty end as stdd_qty ,
  59. case when unit.curr is null or unit.curr = '' then item.curr else unit.curr end as curr,
  60. case when unit.curr is null or unit.curr = '' then fn_code_nm('CURR',item.curr) else fn_code_nm('CURR',unit.curr) end as curr_nm,
  61. case when unit.unit_amt is null or unit.unit_amt = 0 then item.store_sale_unit_amt else unit.unit_amt end as unit_amt,
  62. case when unit.unit_target_cd is null or unit.unit_target_cd = '' then 'Y' else unit.unit_target_cd end as unit_target_cd,
  63. case when unit.unit_target_cd is null or unit.unit_target_cd = '' then fn_code_nm('DSTRBT_COST_UNIT','Y') else fn_code_nm('DSTRBT_COST_UNIT',unit.unit_target_cd) end as unit_target_nm,
  64. nvl(item.unit_amt,0) as spply_unit_amt
  65. from brand_item_unit_info item
  66. 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}
  67. and unit.cont_stt_dt = #{contSttDt} and unit.cont_end_dt = #{contEndDt}
  68. where item.brand_id = #{brandId}
  69. </select>
  70. <select id="selectStoreItemUnitContDateInfo" resultType="String">
  71. select /* selectStoreItemUnitContDateInfo */
  72. nvl(max(cont_end_dt),'') as cont_end_dt
  73. from store_item_unit_info
  74. where brand_id = #{brandId}
  75. and store_id = #{storeId}
  76. and cont_end_dt between #{contSttDt} and #{contEndDt}
  77. </select>
  78. <update id="updateStoreItemUnitContEnd" >
  79. update /* updateStoreItemUnitContEnd */
  80. store_item_unit_info
  81. set cont_end_dt = date_format(DATE_SUB(date_format(#{contSttDt},'%Y%m%d'), INTERVAL 1 DAY),'%Y%m%d')
  82. where brand_id = #{brandId}
  83. and store_id = #{storeId}
  84. and cont_end_dt = #{contEndDt}
  85. </update>
  86. <insert id="insertMergStoreItemUnitInfo" >
  87. insert into /** Merge insertMergStoreItemUnitInfo */
  88. store_item_unit_info
  89. (store_unit_unq_no, cont_stt_dt, cont_end_dt, unit,
  90. curr, unit_amt, store_id, brand_id, short_cont_file_no,
  91. unit_target_cd, item_id, stdd_qty, brand_unit_unq_no,
  92. sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
  93. values
  94. <foreach collection="gridUpdateData" item="item" separator=",">
  95. ( fn_get_dealno(34,''), #{contSttDt}, #{contEndDt}, #{item.unit},
  96. #{item.curr}, #{item.unitAmt}, #{storeId}, #{brandId}, #{item.shortContFileNo},
  97. #{item.unitTargetCd}, #{item.itemId}, #{item.stddQty}, #{item.brandUnitUnqNo},
  98. NOW(), #{userId}, NOW(), #{userId})
  99. </foreach>
  100. on duplicate key
  101. update
  102. sys_chg_dttm = now()
  103. , sys_chg_id = #{userId}
  104. , cont_stt_dt = VALUES(cont_stt_dt)
  105. , cont_end_dt = VALUES(cont_end_dt)
  106. , unit = VALUES(unit)
  107. , curr = VALUES(curr)
  108. , unit_amt = VALUES(unit_amt)
  109. , unit_target_cd = VALUES(unit_target_cd)
  110. , stdd_qty = VALUES(stdd_qty)
  111. </insert>
  112. </mapper>