insert into store_base_info ( brand_id,store_id,store_nm,store_dvsn,mbl_no ,open_dt,close_dt,loan_mgnt_unq_no,loan_dvsn,limit_amt, rtn_proc_dvsn ,zip_no,addr1,addr2,tel_no,fax_no ,emal_addr,store_st_cd,bsns_reg_no,corp_reg_no,ctgr_bsns ,bsns_cndt, bnk_cd, acct_no, owner_nm,del_yn,area_cd,lat_x, whs_use_yn ,long_y,oq_brand_id,oq_store_id,sys_reg_dttm,sys_reg_id,sys_chg_dttm,sys_chg_id ) values ( #{entity.brandId},#{entity.storeId},#{entity.storeNm},#{entity.storeDvsn},#{entity.mblNo}, #{entity.openDt},#{entity.closeDt},#{entity.loanMgntUnqNo},#{entity.loanDvsn},#{entity.limitAmt},#{entity.rtnProcDvsn}, #{entity.zipNo},#{entity.addr1},#{entity.addr2},#{entity.telNo},#{entity.faxNo}, #{entity.emalAddr},#{entity.storeStCd},#{entity.bsnsRegNo},#{entity.corpRegNo},#{entity.ctgrBsns}, #{entity.bsnsCndt},#{entity.bnkCd}, #{entity.acctNo}, #{entity.ownerNm},'N',#{entity.areaCd},#{entity.latX},#{entity.whsUseYn}, #{entity.longY},null,null,now(),#{userId},now(),#{userId} ) update store_base_info set store_nm = #{entity.storeNm} ,store_dvsn = #{entity.storeDvsn} ,mbl_no = #{entity.mblNo} ,open_dt = #{entity.openDt} ,close_dt = case when #{entity.storeStCd} = 'ST03' then date_format(now(),'%Y%m%d') else null end ,loan_mgnt_unq_no = #{entity.loanMgntUnqNo} ,loan_dvsn = #{entity.loanDvsn} ,rtn_proc_dvsn = #{entity.rtnProcDvsn} ,limit_amt = #{entity.limitAmt} ,zip_no = #{entity.zipNo} ,addr1 = #{entity.addr1} ,addr2 = #{entity.addr2} ,tel_no = #{entity.telNo} ,fax_no = #{entity.faxNo} ,emal_addr = #{entity.emalAddr} ,store_st_cd = #{entity.storeStCd} ,ctgr_bsns = #{entity.ctgrBsns} ,bsns_cndt = #{entity.bsnsCndt} ,bnk_cd = #{entity.bnkCd} ,acct_no = #{entity.acctNo} ,owner_nm = #{entity.ownerNm} ,area_cd = #{entity.areaCd} ,lat_x = #{entity.latX} ,long_y = #{entity.longY} ,whs_use_yn = #{entity.whsUseYn} ,sys_chg_dttm = now() ,sys_chg_id = #{userId} where brand_id = #{entity.brandId} and store_id = #{entity.storeId} update store_base_info set sys_chg_dttm = now() ,sys_chg_id = #{userId} ,store_st_cd = 'ST03' where 1=1 and brand_id = #{brandId} and brand_id in (select brand_id from affl_shop_base_info where affl_shop_id = #{afflShopId})