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.MatOptionEntity; import com.yc.sdk.shopping.entity.OptionEntity; import com.yc.service.BaseService; @Service("MatOptionImpl") @Scope("prototype") public class MatOptionImpl extends BaseService implements MatOptionIfc { @Override public boolean hasMatOption(String matCode) { String sql = "set nocount on ; \n" + " if exists(select top 1 1 \n" + " from t710107 a join t110503 b on a.doccode = b.DocCode \n" + " join t710116 c on a.OptionId = c.OptionId \n" + " where b.MatCode = "+GridUtils.prossSqlParm(matCode)+" ) \n" + " select 1 \n" + " else " + " select 0 \n" ; try { Integer ret = this.jdbcTemplate.queryForObject(sql,Integer.class ) ; if (ret != null && ret.intValue() == 1) { return true ; }else { return false ; } }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return false ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } @Override public List getMatOption(String matCode) { String sql = "set nocount on ; \n" + " select b.MatCode,a.OptionId,c.OptionName,a.Value, \n" + " a.Required,a.Digit,a.Subtract,a.Price,\n" + " a.PricePrefix,a.Points,a.PointsPrefix,a.Weight,a.WeightPrefix ,c.Type \n" + " from t710107 a join t110503 b on a.doccode = b.DocCode \n" + " join t710116 c on a.OptionId = c.OptionId \n" + " where b.MatCode = "+GridUtils.prossSqlParm(matCode)+" \n" + " order by a.OptionId,a.Value \n" ; List> list = null; try { list = this.jdbcTemplate.queryForList(sql) ; List matOptionEntityList = new ArrayList() ; for(int i = 0 ; list != null && i < list.size();i++) { Map map = list.get(i) ; MatOptionEntity matOptionEntity = new MatOptionEntity() ; matOptionEntity.setMatCode(map.get("MatCode") == null ? "": (String)map.get("MatCode")); matOptionEntity.setOptionId(map.get("OptionId") == null ? null: (Integer)map.get("OptionId")); matOptionEntity.setOptionName(map.get("OptionName") == null ? "": (String)map.get("OptionName")); matOptionEntity.setValue(map.get("Value") == null ? "": (String)map.get("Value")); matOptionEntity.setRequired(map.get("Required") == null|| (Integer)map.get("Required") == 0 ? false: true); matOptionEntity.setDigit(map.get("Digit") == null ? 0.00: Double.parseDouble(map.get("Digit").toString())); matOptionEntity.setSubtract(map.get("Subtract") == null ? null: (Integer)map.get("Subtract")); matOptionEntity.setPrice(map.get("Price") == null ? 0.00: Double.parseDouble(map.get("Price").toString())); matOptionEntity.setPricePrefix(map.get("PricePrefix") == null ? "": (String)map.get("PricePrefix")); matOptionEntity.setPoints(map.get("Points") == null ? 0.00: Double.parseDouble(map.get("Points").toString())); matOptionEntity.setWeight(map.get("Weight") == null ? 0.00: Double.parseDouble(map.get("Weight").toString())); matOptionEntity.setWeightPrefix(map.get("WeightPrefix") == null ? "": (String)map.get("WeightPrefix")); matOptionEntity.setType(map.get("Type") == null ? "": (String)map.get("Type")); matOptionEntityList.add( matOptionEntity) ; } return matOptionEntityList; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } @Override public List getOptionEntityRequired(String matCode) { String sql = "set nocount on ; \n" + " select a.OptionId,a.OptionName ,a.Type \n " + " from t710116 a \n" + " where exists (select 1 from t710107 b join t110503 c on b.DocCode = c.DocCode \n" + " where b.OptionId = a.OptionId and c.MatCode = "+GridUtils.prossSqlParm(matCode)+" and b.Required = 1 ) \n " + " order by a.OptionId \n" ; List> list = null; try { list = this.jdbcTemplate.queryForList(sql) ; List optionEntityList = new ArrayList() ; for(int i = 0 ; list != null && i < list.size();i++) { Map map = list.get(i) ; OptionEntity optionEntity = new OptionEntity() ; optionEntity.setOptionId(map.get("OptionId") == null ? null: (Integer)map.get("OptionId")); optionEntity.setOptionName(map.get("OptionName") == null ? "": (String)map.get("OptionName")); optionEntity.setType(map.get("Type") == null ? "": (String)map.get("Type")); optionEntityList.add( optionEntity) ; } return optionEntityList; }catch(DataAccessException e ) { if (e instanceof EmptyResultDataAccessException){ return null ; }else { e.printStackTrace(); throw e; } }catch(Exception e){ e.printStackTrace(); throw e; } } //检查是否必录控件 @Override public boolean isRequired(List list,Integer optionId) { for (int k = 0 ;list != null && k < list.size() ;k++) { if (list.get(k).getOptionId().equals(optionId)&& list.get(k).getRequired()) { return true ; } } return false ; } }