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.exception.ApplicationException;
|
import com.yc.sdk.shopping.entity.MatDiscountEntity;
|
import com.yc.service.BaseService;
|
|
@Service("MatDiscountImpl")
|
@Scope("prototype")
|
public class MatDiscountImpl extends BaseService implements MatDiscountIfc {
|
|
@Override
|
public List<MatDiscountEntity> getMatDiscount(String matCode,String cltType) {
|
if (matCode == null) return null;
|
if (cltType == null || "".equals(cltType)) cltType = "临时客户" ;
|
String sql = "set nocount on ; \n"
|
+ " select b.MatCode,a.Digit,a.Price \n"
|
+ " from t710108 a join t110503 b on a.DocCode = b.DocCode \n"
|
+ " where b.MatCode = " +GridUtils.prossSqlParm(matCode) +" and a.CltType = " + GridUtils.prossSqlParm(cltType) +" \n"
|
+ " and convert(varchar(10),getdate(),120) between a.DateStart and a.DateEnd \n "
|
+ " order by a.Priority asc \n" ;
|
List<MatDiscountEntity> matDiscountList = new ArrayList<MatDiscountEntity>() ;
|
try {
|
List<Map<String,Object>> list = this.jdbcTemplate.queryForList(sql) ;
|
|
for (int i = 0 ; list != null && i < list.size();i++) {
|
Map<String,Object> map = list.get(i) ;
|
MatDiscountEntity matDis = new MatDiscountEntity() ;
|
matDis.setMatCode(map.get("MatCode") == null ? "": (String)map.get("MatCode"));
|
matDis.setDigit(map.get("Digit") == null ? 0.00: Double.parseDouble(map.get("Digit").toString()));
|
matDis.setPrice(map.get("Price") == null ? null: Double.parseDouble(map.get("Price").toString()));
|
matDiscountList.add(matDis) ;
|
}
|
} catch(DataAccessException e ) {
|
if (e instanceof EmptyResultDataAccessException){
|
return null ;
|
}else {
|
e.printStackTrace();
|
throw new ApplicationException(e.getMessage());
|
}
|
}catch(Exception e){
|
e.printStackTrace();
|
throw e;
|
}
|
return matDiscountList ;
|
}
|
|
}
|