xinyb
2024-07-18 80430d52f7716e3eb3e517dc96f94c4a6f9657bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 ;
    }
 
}