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
package com.shlanbao.tzsc.pms.cos.maintain.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import com.shlanbao.tzsc.utils.tools.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.CosMatPriceMaintainDaoI;
import com.shlanbao.tzsc.base.dao.MdUnitDaoI;
import com.shlanbao.tzsc.base.mapping.CosMatPriceMaintain;
import com.shlanbao.tzsc.base.mapping.MdMat;
import com.shlanbao.tzsc.base.mapping.MdUnit;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.pms.cos.maintain.beans.MaintainBean;
import com.shlanbao.tzsc.pms.cos.maintain.beans.UnitBean;
import com.shlanbao.tzsc.pms.cos.maintain.service.MaintainServiceI;
 
import javax.servlet.http.HttpServletRequest;
 
@Service
public class MaintainServiceImpl extends BaseService implements MaintainServiceI {
    @Autowired
    private MdUnitDaoI mdUnitDao;
    @Autowired
    private CosMatPriceMaintainDaoI cosMatPriceMaintainDao;
    @Autowired
    private HttpServletRequest request;
 
    @Override
    public DataGrid queryCosMaintain(MaintainBean maintainBean,PageParams pageParams) throws Exception {
        String hql = "from CosMatPriceMaintain o where 1=1 and o.del=0 ";
        StringBuffer params = new StringBuffer();
        if (StringUtil.notNull(maintainBean.getMatType())){
            params.append(" and o.mdMat.mdMatType.id = '"+maintainBean.getMatType()+"'");
        }
        //辅料名称
        if(StringUtil.notNull(maintainBean.getMatName())&&!"全部".equals(maintainBean.getMatName())) {
            params.append(" and o.mdMat.name like '%"+maintainBean.getMatName()+"%'");
        }
 
        //时间
        if(StringUtil.notNull(maintainBean.getDate1())){
            hql = hql.concat(" and to_char(o.takeeffectDate,'yyyy-mm-dd') >= '" + maintainBean.getDate1()+"'");
        }
        if(StringUtil.notNull(maintainBean.getDate2())){
            hql = hql.concat(" and to_char(o.takeeffectDate,'yyyy-mm-dd') <= '" + maintainBean.getDate2()+"'");
        }
        //hql = hql.concat(StringUtil.fmtDateBetweenParams("o.takeeffectDate", maintainBean.getDate1(), maintainBean.getDate2()));
 
        List<CosMatPriceMaintain> cmp = cosMatPriceMaintainDao.queryByPage(hql.concat(params.toString()),pageParams);
        List<MaintainBean> beans = new ArrayList<MaintainBean>();
        for(CosMatPriceMaintain c : cmp){
            if (HbUtils.isProxy(c)){
                c = HbUtils.deproxy(c);
            }
            MaintainBean bean = new MaintainBean();
            if(null != c.getMdMat()) {//辅料
                bean.setMatId(c.getMdMat().getId());
                 bean.setMatName(c.getMdMat().getName());
            }
            if(null != c.getMdShift()) //班次
                bean.setShiftName(c.getMdShift().getName());
 
            if(null != c.getMdUnit())//单位
                bean.setUnitName(c.getMdUnit().getName());
            BeanConvertor.copyProperties(c, bean);
            FillUserInfoUtil.fillCreateAndUpdateUserInfo(c,bean);
            beans.add(bean);
        }
        hql = "select count(*) from CosMatPriceMaintain o where 1=1 and o.del=0 ";
 
        long total = cosMatPriceMaintainDao.queryTotal(hql.concat(params.toString()));
 
        return new DataGrid(beans,total);
    }
 
    @LogAnno(operateType = "添加物料成本维护信息")
    @Override
    public void addCosMaintain(MaintainBean maintainBean) throws Exception {
        CosMatPriceMaintain cosMatPriceMaintain = new CosMatPriceMaintain();
        BeanConvertor.copyProperties(maintainBean,cosMatPriceMaintain);
        cosMatPriceMaintain.setMdMat(new MdMat(maintainBean.getMatId()));
        /*if(!StringUtils.isEmpty(maintainBean.getShiftId())){
            cosMatPriceMaintain.setMdShift(new MdShift(maintainBean.getShiftId()));
        }*/
        cosMatPriceMaintain.setMdUnit(new MdUnit(maintainBean.getUnitId()));
        cosMatPriceMaintain.setDel(0L);
        FillUserInfoUtil.fillCreateUserInfo(cosMatPriceMaintain,request);
        cosMatPriceMaintainDao.save(cosMatPriceMaintain);
    }
 
    @LogAnno(operateType = "编辑物料成本维护信息")
    @Override
    public void editCosMaintain(MaintainBean maintainBean) throws Exception {
        CosMatPriceMaintain cosMatPriceMaintain = cosMatPriceMaintainDao.findById(CosMatPriceMaintain.class, maintainBean.getId());
        cosMatPriceMaintain.setMdUnit(new MdUnit(maintainBean.getUnitId()));
        cosMatPriceMaintain.setMdMat(new MdMat(maintainBean.getMatId()));
        /*cosMatPriceMaintain.setMdShift(new MdShift(maintainBean.getShiftId()));*/
        FillUserInfoUtil.fillUpdateUserInfo(cosMatPriceMaintain,request);
        BeanConvertor.copyProperties(maintainBean,cosMatPriceMaintain);
    }
 
    @Override
    public void delCosMaintain(String id) throws Exception {
        cosMatPriceMaintainDao.findById(CosMatPriceMaintain.class, id).setDel(1L);
    }
 
    /**
    * @Title: getMaintainListByBean
    * @Description: 根据Bean获取List
    * @param  maintainBean
    * @return List<CosMatPriceMaintain>    返回类型
    * @throws
     */
    @Override
    public List<CosMatPriceMaintain> getMaintainListByBean(MaintainBean maintainBean){
        StringBuffer hql=new StringBuffer();
        hql.append("from CosMatPriceMaintain o where 1=1 and o.del=0 ");
        if(StringUtil.notNull(maintainBean.getMatName())){
            hql.append("and  o.mdMat.name='"+maintainBean.getMatName()+"' ");
        }
        return cosMatPriceMaintainDao.query(hql.toString());
    }
 
    @Override
    public MaintainBean getMaintainBean(String id) throws Exception {
        CosMatPriceMaintain cosMatPriceMaintain = cosMatPriceMaintainDao.findById(CosMatPriceMaintain.class, id);
        MaintainBean bean = new MaintainBean();
        if(null != cosMatPriceMaintain.getMdMat()) bean.setMatName(cosMatPriceMaintain.getMdMat().getName());
 
        if(null != cosMatPriceMaintain.getMdMat()) bean.setMatId(cosMatPriceMaintain.getMdMat().getId());
 
        if(null != cosMatPriceMaintain.getMdShift()) bean.setShiftId(cosMatPriceMaintain.getMdShift().getId());
 
        if(null != cosMatPriceMaintain.getMdUnit()) bean.setUnitId(cosMatPriceMaintain.getMdUnit().getId());
 
        if(null != cosMatPriceMaintain.getMdUnit()) bean.setUnitName(cosMatPriceMaintain.getMdUnit().getName());
 
        BeanConvertor.copyProperties(cosMatPriceMaintain,bean);
        return bean;
    }
 
    @Override
    public List<UnitBean> queryAllUtil() throws Exception {
        return BeanConvertor.copyList(mdUnitDao.query("from MdUnit o where o.del='0' and o.enable=1"), UnitBean.class);
    }
}