123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.oqpo.api.mapper.stinfo.StoreItemUnitMapper">
- <select id="selectStoreItemUnitGridList" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
- select /* selectStoreItemUnitGridList */
- 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,
- 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,
- date_format(iunit.sys_reg_dttm,'%Y.%m.%d') as sys_reg_dttm, iunit.item_cnt
- from (
- select brand_id, store_id, cont_stt_dt, cont_end_dt, min(sys_reg_dttm) as sys_reg_dttm, count(*) as item_cnt
- from store_item_unit_info
- where brand_id = #{sBrandId}
- <if test="sStoreNm != null and sStoreNm != ''">
- and store_nm = concat('%',#{sStoreNm},'%')
- </if>
- and unit_target_cd = 'Y'
- group by brand_id, store_id, cont_stt_dt, cont_end_dt
- ) iunit
- <choose>
- <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
- <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
- <if test="gridRequest.sord == 'asc'.toString()">
- order by store_nm asc
- </if>
- <if test="gridRequest.sord == 'desc'.toString()">
- order by store_nm desc
- </if>
- </if>
- </when>
- <otherwise>
- order by store_nm asc
- </otherwise>
- </choose>
- <if test="gridRequest.pagingYn == true">
- limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
- </if>
- </select>
- <select id="selectStoreItemUnitGridCnt" resultType="int">
- select /*selectStoreItemUnitGridCnt*/
- count(*)
- from (
- select distinct brand_id, store_id, cont_stt_dt, cont_end_dt
- from store_item_unit_info
- where brand_id = #{sBrandId}
- <if test="sStoreNm != null and sStoreNm != ''">
- and store_nm = concat('%',#{sStoreNm},'%')
- </if>
- and unit_target_cd = 'Y'
- ) iunit
- </select>
- <select id="selectStoreItemUnitInfo" resultType="com.oqpo.api.entity.stinfo.StoreItemUnitEntity">
- select /*selectStoreItemUnitInfo*/
- unit.store_unit_unq_no, item.brand_id, item.item_id, item.item_nm,
- 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,
- 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,
- case when unit.unit is null or unit.unit = '' then item.unit else unit.unit end as unit ,
- 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 ,
- case when nvl(unit.stdd_qty,0) = 0 then item.store_sale_stdd_qty else unit.stdd_qty end as stdd_qty ,
- case when unit.curr is null or unit.curr = '' then item.curr else unit.curr end as curr,
- 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,
- 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,
- 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,
- 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,
- nvl(item.unit_amt,0) as spply_unit_amt
- from brand_item_unit_info item
- 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}
- and unit.cont_stt_dt = #{contSttDt} and unit.cont_end_dt = #{contEndDt}
- where item.brand_id = #{brandId}
- </select>
- <select id="selectStoreItemUnitContDateInfo" resultType="String">
- select /* selectStoreItemUnitContDateInfo */
- nvl(max(cont_end_dt),'') as cont_end_dt
- from store_item_unit_info
- where brand_id = #{brandId}
- and store_id = #{storeId}
- and cont_end_dt between #{contSttDt} and #{contEndDt}
- </select>
- <update id="updateStoreItemUnitContEnd" >
- update /* updateStoreItemUnitContEnd */
- store_item_unit_info
- set cont_end_dt = date_format(DATE_SUB(date_format(#{contSttDt},'%Y%m%d'), INTERVAL 1 DAY),'%Y%m%d')
- where brand_id = #{brandId}
- and store_id = #{storeId}
- and cont_end_dt = #{contEndDt}
- </update>
- <insert id="insertMergStoreItemUnitInfo" >
- insert into /** Merge insertMergStoreItemUnitInfo */
- store_item_unit_info
- (store_unit_unq_no, cont_stt_dt, cont_end_dt, unit,
- curr, unit_amt, store_id, brand_id, short_cont_file_no,
- unit_target_cd, item_id, stdd_qty, brand_unit_unq_no,
- sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
- values
- <foreach collection="gridUpdateData" item="item" separator=",">
- ( fn_get_dealno(34,''), #{contSttDt}, #{contEndDt}, #{item.unit},
- #{item.curr}, #{item.unitAmt}, #{storeId}, #{brandId}, #{item.shortContFileNo},
- #{item.unitTargetCd}, #{item.itemId}, #{item.stddQty}, #{item.brandUnitUnqNo},
- NOW(), #{userId}, NOW(), #{userId})
- </foreach>
- on duplicate key
- update
- sys_chg_dttm = now()
- , sys_chg_id = #{userId}
- , cont_stt_dt = VALUES(cont_stt_dt)
- , cont_end_dt = VALUES(cont_end_dt)
- , unit = VALUES(unit)
- , curr = VALUES(curr)
- , unit_amt = VALUES(unit_amt)
- , unit_target_cd = VALUES(unit_target_cd)
- , stdd_qty = VALUES(stdd_qty)
- </insert>
- </mapper>
|