zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.shlanbao.tzsc.pms.md.eqpStopMaintain.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import com.shlanbao.tzsc.base.mapping.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
 
import com.shlanbao.tzsc.base.dao.BaseDaoI;
import com.shlanbao.tzsc.base.dao.EqpStopMaintainDaoI;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.pms.md.eqpStopMaintain.EqpStopMaintainBean;
import com.shlanbao.tzsc.pms.md.eqpStopMaintain.service.EqpStopMaintainServiceI;
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import com.shlanbao.tzsc.utils.tools.DateUtil;
import com.shlanbao.tzsc.utils.tools.StringUtil;
 
@Service
public class EqpStopMaintainServiceImpl extends BaseService implements
EqpStopMaintainServiceI  {
 
    @Autowired
    private EqpStopMaintainDaoI eqpStopMaintainDaoI;
 
    @Autowired
    private BaseDaoI<Object> baseDao;
 
    @Override
    public DataGrid getAllStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
        String hql="from EqpStopMaintain o left join fetch o.mdteam t left join fetch  o.mdeqp e join fetch  o.mdca s  where 1=1";//1 deleted data is not visible
        String params="";
        if(StringUtil.notEmpty(eqpStopMaintainBean.getsDate())){
            params = params.concat(" and to_char(o.actualDate,'yyyy-MM') = '" + eqpStopMaintainBean.getsDate() + "'");
        }
        if(StringUtil.notEmpty(eqpStopMaintainBean.getTeamId())){
            params = params.concat(" and t.code = '" + eqpStopMaintainBean.getTeamId() + "'");
        }
        if(StringUtil.notEmpty(eqpStopMaintainBean.getEqptype())){
            params = params.concat(" and s.id = '" + eqpStopMaintainBean.getEqptype() + "'");
        }
        if(StringUtil.notEmpty(eqpStopMaintainBean.getEqpId())){
            params = params.concat(" and e.id = '" + eqpStopMaintainBean.getEqpId() + "'");
        }
        if(StringUtil.notEmpty(eqpStopMaintainBean.getContent())){
            params = params.concat(" and o.content = '" + eqpStopMaintainBean.getContent() + "'");
        }
 
        params = params.concat(" order by to_char(o.actualDate,'yyyy-MM-dd')");
 
        List<EqpStopMaintain> rows=eqpStopMaintainDaoI.query(hql.concat(params));
        List<EqpStopMaintainBean> orderBeans = new ArrayList<EqpStopMaintainBean>();
 
        EqpStopMaintainBean bean = null;
try {
 
            for (EqpStopMaintain eqpStopMaintain : rows) {
 
                bean = BeanConvertor.copyProperties(eqpStopMaintain, EqpStopMaintainBean.class);
                String realStim = DateUtil.datetoStr(eqpStopMaintain.getActualDate(), "yyyy-MM-dd");
                bean.setActualDate(realStim);
                if (eqpStopMaintain.getMdteam()!=null) {
                    bean.setTeamname(eqpStopMaintain.getMdteam().getName());
                    bean.setTeamId(eqpStopMaintain.getMdteam().getId());
                }
                if (eqpStopMaintain.getMdShift()!=null) {
                    bean.setShiftName(eqpStopMaintain.getMdShift().getName());
                    bean.setShiftId(eqpStopMaintain.getMdShift().getId());
                }
                if (eqpStopMaintain.getMdeqp()!=null) {
                    bean.setEqpId(eqpStopMaintain.getMdeqp().getId());
                    bean.setEqptype(eqpStopMaintain.getMdeqp().getMdEqpType().getMdEqpCategory().getCode());
                    bean.setEquipment(eqpStopMaintain.getMdeqp().getEquipmentName());
                }
                bean.setContent(eqpStopMaintain.getContent());
                bean.setNum(eqpStopMaintain.getNum());
                bean.setFree(eqpStopMaintain.getFree());
                bean.setFree2(eqpStopMaintain.getFree2());
                bean.setFree1(eqpStopMaintain.getFree1());
                orderBeans.add(bean);
 
                bean = null;
            }
            return new DataGrid(orderBeans, 0L);
 
        } catch (Exception e) {
 
            log.error("POVO转换异常", e);
 
        }
 
        return null;
 
    }
 
    @Override
    public void addStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
        EqpStopMaintain o = BeanConvertor.copyProperties(eqpStopMaintainBean, EqpStopMaintain.class);
 
        List<?> shiftId = eqpStopMaintainDaoI.queryBySql("select shift from sch_calendar where to_char(date_,'yyyy-mm-dd') = '"+eqpStopMaintainBean.getActualDate()+"' and team = "+eqpStopMaintainBean.getTeamId()+" and workshop = 1 ");
 
 
        if (shiftId!=null && shiftId.size()>0) {
            o.setMdShift(new MdShift(shiftId.get(0).toString()));
        }
 
        /*Date abc=DateUtil.strToDate(eqpStopMaintainBean.getActualDate()+" 00:00:00","yyyy-MM-dd HH:mm:ss");
        o.setActualDate(abc);*/
 
        o.setMdteam(new MdTeam(eqpStopMaintainBean.getTeamId()));
        o.setMdeqp(new MdEquipment(eqpStopMaintainBean.getEqpId()));
/*        String ceh=eqpStopMaintainDaoI.queryBySql("select EQP_TYPE_ID from MD_EQUIPMENT where code = ?", eqpStopMaintainBean.getEqptype()).get(0).toString();
    o.setMdca(new MdEqpCategory(ceh));*/
        o.setMdca(new MdEqpCategory(eqpStopMaintainBean.getEqptype()));
        eqpStopMaintainDaoI.save(o);
 
    }
 
 
 
    @Override
    public void editStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
        EqpStopMaintain o = BeanConvertor.copyProperties(eqpStopMaintainBean, EqpStopMaintain.class);
        List<?> shiftId = eqpStopMaintainDaoI.queryBySql("select shift from sch_calendar where to_char(date_,'yyyy-mm-dd') = '"+eqpStopMaintainBean.getActualDate()+"' and team = "+eqpStopMaintainBean.getTeamId()+" and workshop = 1 ");
 
 
        if (shiftId!=null && shiftId.size()>0) {
            o.setMdShift(new MdShift(shiftId.get(0).toString()));
        }
        o.setMdteam(new MdTeam(eqpStopMaintainBean.getTeamId()));
        o.setMdeqp(new MdEquipment(eqpStopMaintainBean.getEqpId()));
        o.setMdca(new MdEqpCategory(eqpStopMaintainBean.getEqptype()));
        EqpStopMaintain s;
        s=o;
        eqpStopMaintainDaoI.update(s);
 
    }
 
 
    @Override
    public EqpStopMaintainBean getStopMaintainById(String id) throws Exception {
/*        return BeanConvertor.copyProperties(eqpStopMaintainDaoI.findById(EqpStopMaintain.class, id),EqpStopMaintainBean.class);
*/
        EqpStopMaintain eqpStopMaintain = eqpStopMaintainDaoI.findById(EqpStopMaintain.class, id);
 
        EqpStopMaintainBean bean = BeanConvertor.copyProperties(eqpStopMaintain, EqpStopMaintainBean.class);
        bean.setEqptype(eqpStopMaintain.getMdca().getId());
        bean.setTeamname(eqpStopMaintain.getMdteam().getName());
        bean.setTeamId(eqpStopMaintain.getMdteam().getId());
        bean.setEquipment(eqpStopMaintain.getMdeqp().getEquipmentName());
        bean.setEqpId(eqpStopMaintain.getMdeqp().getId());
        bean.setFree2(eqpStopMaintain.getMdca().getName());
 
        return bean;
 
    }
 
    @Override
    public void deleteStopMaintain(String id) throws Exception {
        eqpStopMaintainDaoI.deleteById(id, EqpStopMaintain.class);
 
    }
 
    @Override
    public void enableStopMaintain(String id,int enable) {
        List<Object> list = new ArrayList<>();
        list.add(enable);
        list.add(id);
        eqpStopMaintainDaoI.updateBySql("update EQP_STOP_MAINTAIN set free1 = ? where id = ?", list);
 
    }
 
 
 
}