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.LangEntity; import com.yc.service.BaseService; @Service("LangImpl") @Scope("prototype") public class LangImpl extends BaseService implements LangIfc { @Override public LangEntity getLang(int langId) { String sql = " set nocount on ; select la_id,la_code,la_remark,image from _sys_language where la_id = "+langId ; ; 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 getLangEntity( map); } @Override public List getLangs() { String sql = " set nocount on ; select la_id,la_code,la_remark,image from _sys_language ;" ; List> list = null ; try { list = this.jdbcTemplate.queryForList(sql) ; List langEntityList = new ArrayList() ; for (int i = 0 ; list != null && i < list.size();i++) { Map map = list.get(i) ; LangEntity langEntity = getLangEntity( map); langEntityList.add(langEntity); } return langEntityList; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } @Override public LangEntity getLangEntity(Map map) { LangEntity langEntity = new LangEntity() ; if (map != null && map.size() > 0) { langEntity.setLangId((Integer)map.get("la_id") == null ? null: (Integer)map.get("la_id")); langEntity.setCode((String)map.get("la_code") == null ? "": (String)map.get("la_code")); langEntity.setLangName((String)map.get("la_remark") == null ? "": (String)map.get("la_remark")); langEntity.setImage((String)map.get("image") == null ? null: (String)map.get("image")); } return langEntity ; } @Override public LangEntity getUserLang(String userCode) { String sql = " set nocount on ; " + " declare @UserCode varchar(50) ,@LangId int; \n" + " select @UserCode = "+GridUtils.prossSqlParm(userCode)+" ; \n" + " if isnull(@UserCode,'') <> '' \n" + " begin \n" + " select @LangId = LangId from _sys_LoginUser where UserCode = @UserCode ; \n" + " end \n " + " if @LangId is null \n" + " begin \n " + " select top 1 @LangId = LangId from t714001 ; \n" + " end \n " + " if @LangId is null \n " + " select top 1 la_id,la_code,la_remark,image from _sys_language ; \n" + " else" + " select top 1 la_id,la_code,la_remark,image from _sys_language where la_id = @LangId ; \n " ; try { Map map = this.jdbcTemplate.queryForMap(sql) ; return getLangEntity( map); }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } }