package com.yc.sdk.shopping.service; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.springframework.context.annotation.Scope; import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.stereotype.Service; import com.yc.action.grid.GridUtils; import com.yc.sdk.shopping.entity.CurrencyEntity; import com.yc.service.BaseService; @Service("CurrencyImpl") @Scope("prototype") public class CurrencyImpl extends BaseService implements CurrencyIfc { @Override public List getCurrencys() { String sql = " set nocount on ; select Currency,CurrencyName,meno,Domestic from t110703 order by Currency ;" ; List> list = null ; try { list = this.jdbcTemplate.queryForList(sql) ; List currencyList = new ArrayList() ; for (int i = 0 ; list != null && i < list.size();i++) { Map map = list.get(i) ; CurrencyEntity currency = getCurrencyEntity( map); currencyList.add(currency); } return currencyList; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } @Override public CurrencyEntity getUserCurrency(String userCode) { String sql = " set nocount on ; " + " declare @UserCode varchar(50) ,@Currency varchar(20); \n" + " select @UserCode = "+GridUtils.prossSqlParm(userCode)+"; \n" + " if isnull(@UserCode,'') <> '' \n" + " begin \n" + " select @Currency = Currency from _sys_LoginUser where UserCode = @UserCode ; \n" + " end \n " + " if isnull(@Currency,'') = '' \n" + " begin \n " + " select top 1 @Currency = Currency from t714001 ; \n" + " end \n " + " if isnull(@Currency,'') = '' \n " + " select top 1 Currency,CurrencyName,meno,Domestic from t110703 where isnull(Domestic,0) = 1 order by Currency ; \n" + " else" + " select top 1 Currency,CurrencyName,meno,Domestic from t110703 where Currency = @Currency order by Currency ; \n " ; Map map = null ; try { map = this.jdbcTemplate.queryForMap(sql) ; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } return getCurrencyEntity( map); } @Override public CurrencyEntity getCurrency(String currency) { String sql = " set nocount on ; select top 1 Currency,CurrencyName,meno,Domestic from t110703 where Currency = "+GridUtils.prossSqlParm(currency)+" order by Currency ;" ; Map map = null ; try { map= this.jdbcTemplate.queryForMap(sql) ; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } return getCurrencyEntity( map); } @Override public CurrencyEntity getCurrencyEntity(Map map) { CurrencyEntity currency = new CurrencyEntity() ; if (map != null && map.size() > 0) { currency.setCurrency((String)map.get("Currency") == null ? "": (String)map.get("Currency")); currency.setCurrencyName((String)map.get("CurrencyName") == null ? "": (String)map.get("CurrencyName")); currency.setCurrencySign((String)map.get("meno") == null ? "": (String)map.get("meno")); currency.setDomestic((Integer)map.get("Domestic") == null ? null: (Integer)map.get("Domestic")); } return currency ; } }