zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.shlanbao.tzsc.pms.cos.matassess.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.CosMatAssessDaoI;
import com.shlanbao.tzsc.base.dao.CosMatAssessParamDaoI;
import com.shlanbao.tzsc.base.dao.MdMatDaoI;
import com.shlanbao.tzsc.base.dao.SchConStdDaoI;
import com.shlanbao.tzsc.base.mapping.CosMatAssess;
import com.shlanbao.tzsc.base.mapping.CosMatAssessParam;
import com.shlanbao.tzsc.base.mapping.MdMat;
import com.shlanbao.tzsc.base.mapping.SchConStd;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.pms.cos.matassess.bean.CosMatAssessParamBean;
import com.shlanbao.tzsc.pms.cos.matassess.service.CosMatAssessParamServiceI;
import com.shlanbao.tzsc.utils.tools.StringUtil;
/**
 * 
* @ClassName: CosMatAssessServiceImpl 
* @Description: 辅料考核版本控制ServiceImpl 
* @author luoliang
* @date 2015-1-7 上午10:44:37 
*
 */
@Service
public class CosMatAssessParamServiceImpl implements CosMatAssessParamServiceI{
 
    
    @Autowired
    private CosMatAssessParamDaoI cosMatAssessParamDao;
    @Autowired
    private CosMatAssessDaoI cosMatAssessDao;
    @Autowired
    private SchConStdDaoI schConStdDaol;
    @Autowired
    private MdMatDaoI mdMatDao;
    
    //添加或修改Bean
    @Override
    public boolean addOrUpdateBean(CosMatAssessParamBean bean) throws Exception {
        CosMatAssessParam cosMatAssessParam=new CosMatAssessParam();
        if(!StringUtil.notNull(bean.getId())){
            bean.setId(null);
        }else{
            cosMatAssessParam=getBeanByIds(bean.getId());
        }
        cosMatAssessParam.setVal(bean.getVal());
        cosMatAssessParam.setRemark(bean.getRemark());
        cosMatAssessParam.setUnitprice(bean.getUnitprice());
        cosMatAssessParam.setUval(bean.getUval());
        cosMatAssessParam.setLval(bean.getLval());
        if(StringUtil.notNull(bean.getMatId())){
            MdMat m=mdMatDao.findById(MdMat.class, bean.getMatId());
            if(m!=null){
                cosMatAssessParam.setMat(m);
            }
        }
        if(StringUtil.notNull(bean.getCid())){
            CosMatAssess c=cosMatAssessDao.findById(CosMatAssess.class, bean.getCid());
            if(c!=null){
                cosMatAssessParam.setCid(c);
            }
        }
        if(StringUtil.notNull(bean.getStdID())){
            SchConStd s=schConStdDaol.findById(SchConStd.class, bean.getStdID());
            if(s!=null){
                cosMatAssessParam.setStdID(s);
            }
        }
        cosMatAssessParamDao.saveOrUpdate(cosMatAssessParam);
        return true;
    }
    //根据ID获取mapping bean
    @Override
    public CosMatAssessParam getBeanByIds(String id) throws Exception {
        return cosMatAssessParamDao.findById(CosMatAssessParam.class, id);
    }
    
    //根据ID获取bean
    @Override
    public CosMatAssessParamBean getBeanById(String id) throws Exception {
        CosMatAssessParam c = cosMatAssessParamDao.findById(CosMatAssessParam.class, id);
        CosMatAssessParamBean b=new CosMatAssessParamBean();
        b.setVal(c.getVal());
        b.setRemark(c.getRemark());
        b.setUnitprice(c.getUnitprice());
        b.setUval(c.getUval());
        b.setLval(c.getLval());
        b.setCid(c.getCid().getId());
        b.setId(c.getId());
        b.setMatId(c.getMat().getId());
        b.setMatName(c.getMat().getName());
        b.setStdID(c.getStdID().getId());
        return b;
    }
    //查询
    @Override
    public List<CosMatAssessParam> queryBeans(CosMatAssessParam bean,PageParams pageParams){
        String hql="from CosMatAssessParam o where 1=1 ";
        StringBuffer params = new StringBuffer();
        if(StringUtil.notNull(bean.getId())) params.append(" and o.id='" + bean.getId() + "'");
        if(bean.getCid()!=null&&StringUtil.notNull(bean.getCid().getId())) params.append(" and o.cid='" + bean.getCid().getId() + "'");
        if(StringUtil.notNull(bean.getMat().getId())) params.append(" and o.mdmat.id='"+bean.getMat().getId()+"'");
        return  cosMatAssessParamDao.queryByPage(hql.concat(params.toString()),pageParams);
    }
    
    //查询
    @Override
    public List<CosMatAssessParam> queryBeansByExpand(CosMatAssessParamBean bean,PageParams pageParams){
        String hql="from CosMatAssessParam o where 1=1 ";
        StringBuffer params = new StringBuffer();
        if(StringUtil.notNull(bean.getId())) params.append(" and o.id='" + bean.getId() + "'");
        if(StringUtil.notNull(bean.getCid())) params.append(" and o.cid='" + bean.getCid() + "'");
        if(StringUtil.notNull(bean.getMatId())) params.append(" and o.mat='"+bean.getMatId()+"'");
        return  cosMatAssessParamDao.queryByPage(hql.concat(params.toString()),pageParams);
    }
    
    //界面中翻页查询
    @Override
    public DataGrid queryBean(CosMatAssessParam bean, PageParams pageParams) throws Exception {
        String hql="from CosMatAssessParam o where 1=1 ";
        StringBuffer params = new StringBuffer();
        if(StringUtil.notNull(bean.getId())) params.append(" and o.id='" + bean.getId() + "'");
        if(bean.getCid()!=null&&StringUtil.notNull(bean.getCid().getId())) params.append(" and o.cid='" + bean.getCid().getId() + "'");
        List<CosMatAssessParam> oldbeans = cosMatAssessParamDao.queryByPage(hql.concat(params.toString()),pageParams);
        List<CosMatAssessParamBean> beans=new ArrayList<CosMatAssessParamBean>();
        for(CosMatAssessParam c:oldbeans){
            CosMatAssessParamBean b=new CosMatAssessParamBean();
            b.setLval(c.getLval());
            b.setRemark(c.getRemark());
            b.setUnitprice(c.getUnitprice());
            b.setUval(c.getUval());
            b.setVal(c.getVal());
            b.setCid(c.getCid().getId());
            b.setId(c.getId());
            b.setMatId(c.getMat().getId());
            b.setMatName(c.getMat().getName());
            b.setStdID(c.getStdID().getId());
            beans.add(b);
        }
        hql = "select count(*) from CosMatAssessParam o where 1=1  ";
        long total = cosMatAssessParamDao.queryTotal(hql.concat(params.toString()));
        
        return new DataGrid(beans,total);
    }
    
}