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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package com.shlanbao.tzsc.pms.equ.trouble.service.impl;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.EqmFixRecDaoI;
import com.shlanbao.tzsc.base.dao.EqmTroubleDaoI;
import com.shlanbao.tzsc.base.dao.EqmTroubleReDaoI;
import com.shlanbao.tzsc.base.interceptor.WorkOrderStatChangeInterceptor;
import com.shlanbao.tzsc.base.mapping.EqmFixRec;
import com.shlanbao.tzsc.base.mapping.EqmTrouble;
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.equ.trouble.beans.EqmTroubleBean;
import com.shlanbao.tzsc.pms.equ.trouble.beans.EqmTroubleInfoBean;
import com.shlanbao.tzsc.pms.equ.trouble.beans.TroubleBean;
import com.shlanbao.tzsc.pms.equ.trouble.service.TroubleServiceI;
import com.shlanbao.tzsc.utils.tools.StringUtil;
 
@Service
public class TroubleServiceImpl  extends BaseService implements TroubleServiceI {
 
    @Autowired
    private EqmTroubleDaoI troubleDao;
    @Autowired
    private EqmTroubleReDaoI eqmtroubleDaoI;
    @Autowired
    private EqmFixRecDaoI eqmFixRecDao;
    
    @Override
    public DataGrid queryTrouble(TroubleBean bean, PageParams pageParams) throws Exception {
        StringBuffer sqlBuffer=new StringBuffer();
        sqlBuffer.append("from EqmTrouble t where 1=1 ");  
        
        if(StringUtil.notNull(bean.getStartDate())){
            sqlBuffer.append("and to_char(t.create_time,'yyyy-MM-dd')>='"+bean.getStartDate()+"' "); 
        }
        if(StringUtil.notNull(bean.getEndDate())){
            sqlBuffer.append("and to_char(t.create_time,'yyyy-MM-dd')<='"+bean.getEndDate()+"' "); 
        }
        if(StringUtil.notNull(bean.getEqu_id())){
            sqlBuffer.append("and t.EQU_ID='"+bean.getEqu_id()+"' ");
        }
        if(StringUtil.notNull(bean.getShift_id())){
            sqlBuffer.append("and t.SHIFT_ID='"+bean.getShift_id()+"' ");
        }
        sqlBuffer.append("order by t.create_time desc ");
        List<EqmTrouble> lists=troubleDao.query(sqlBuffer.toString());
        long total=troubleDao.queryTotal("select count(*) "+sqlBuffer.toString());
        return new DataGrid(lists,total);
    }
 
    @Override
    public DataGrid queryTrouble(EqmTroubleBean eqmtroubleBean, PageParams pageParams) throws Exception {
        /*StringBuilder hql=new StringBuilder();
        hql.append(" from EqmTrouble t where 1=1 and t.del='0' ");
        if(StringUtil.notNull(eqmtroubleBean.getMdWorkshopId()) )
            hql.append(" and t.mdEquipment.mdWorkshop.id='"+eqmtroubleBean.getMdWorkshopId()+"' ");
        if(StringUtil.notNull(eqmtroubleBean.getMdEqpCategoryId()))
            hql.append(" and t.mdEquipment.mdEqpType.mdEqpCategory.id='"+eqmtroubleBean.getMdEqpCategoryId()+"' ");
        if(StringUtil.notNull(eqmtroubleBean.getMdEqpTypeId()))
            hql.append(" and t.mdEquipment.mdEqpType.id='"+eqmtroubleBean.getMdEqpTypeId()+"' ");
        if(StringUtil.notNull(eqmtroubleBean.getMdEquipmentId()))
            hql.append(" and t.mdEquipment.id='"+eqmtroubleBean.getMdEquipmentId()+"' ");
        if(StringUtil.notNull(eqmtroubleBean.getMdShiftId()))
            hql.append(" and t.mdShift.id='"+eqmtroubleBean.getMdShiftId()+"' ");
        hql.append(StringUtil.fmtDateBetweenParams("t.fault_date", eqmtroubleBean.getRuntime(), eqmtroubleBean.getEndtime()));    
        List<EqmTrouble> troubles=eqmtroubleDaoI.queryByPage(hql.toString(), pageParams);
        List<EqmTroubleBean> eqmTroubleBeans=new ArrayList<EqmTroubleBean>();
        for (EqmTrouble eqmTrouble : troubles) {
            EqmTroubleBean bean=BeanConvertor.copyProperties(eqmTrouble, EqmTroubleBean.class);
            if(eqmTrouble.getMdShift()!=null){
                bean.setMdShiftId(eqmTrouble.getMdShift().getId());
                bean.setMdShiftName(eqmTrouble.getMdShift().getName());
            }
            if(eqmTrouble.getMdEquipment()!=null){
                bean.setMdEquipmentId(eqmTrouble.getMdEquipment().getId());
                bean.setMdEquipmentName(eqmTrouble.getMdEquipment().getEquipmentName());
            }
            bean.setFaultDate(DateUtil.formatDateToString(eqmTrouble.getFault_date(),"yyyy-MM-dd"));
            eqmTroubleBeans.add(bean);
        }
        long total=eqmtroubleDaoI.queryTotal("select count(*) "+hql.toString());
        return new DataGrid(eqmTroubleBeans, total);*/
        return null;
    }
    
    /**
     * 张璐
     * 设备信息表查询--测试用
     * @return
     */
    @Override
    public List<EqmTroubleInfoBean> queryTroubleInfo(EqmTroubleInfoBean troubleBean){
        /*StringBuffer sb=new StringBuffer();
        sb.append("SELECT et.id,et.md_eqp_type_id,et.trouble_part_description,et.part_code_description,et.trouble_phenomenon_description,et.trouble_reason_description,et.trouble_code,et.trouble_phenomenon,et.trouble_reason from EQM_TROUBLE_INFO et where 1=1 ");
        if(StringUtil.notNull(troubleBean.getTroubleName())){
            sb.append(" and et.trouble_reason_description='"+troubleBean.getTroubleName()+"'");
        }
        List<?> list = eqmtroubleDaoI.queryBySql(sb.toString());
        List<EqmTroubleInfoBean> listBean = new ArrayList<EqmTroubleInfoBean>();
        if(list.size()>0){
            for(Object b:list){
                Object[]temp = (Object[]) b;
                EqmTroubleInfoBean bean = new EqmTroubleInfoBean();
                bean.setId(temp[0].toString());
                if(null!=temp[1]){
                    bean.setEqp_DES(temp[1].toString());
                }
                bean.setTrouble_part_description(temp[2].toString());
                bean.setPart_code_description(temp[3].toString());
                bean.setTrouble_phenomenon_description(temp[4].toString());
                bean.setTrouble_reason_description(temp[5].toString());
                bean.setTrouble_code(temp[6].toString());
                bean.setTrouble_phenomenon((int) temp[7]);
                bean.setTrouble_reason(temp[8].toString());
                listBean.add(bean);
            }
        }
        return listBean;*/
        
        StringBuffer sb=new StringBuffer(1000);
        sb.append("SELECT id,code,description,type,parent_id from EQM_TROUBLE_INFO  where 1=1 ");
        if(StringUtil.notNull(troubleBean.getParent_id())){
            sb.append(" and parent_id='"+troubleBean.getParent_id()+"'");
        }
        sb.append(" ORDER BY type");
        
        List<?> list = eqmtroubleDaoI.queryBySql(sb.toString());
        List<EqmTroubleInfoBean> listBean = new ArrayList<EqmTroubleInfoBean>();
        if(list.size()>0){
            for(Object b:list){
                Object[]temp = (Object[]) b;
                EqmTroubleInfoBean bean = new EqmTroubleInfoBean();
                bean.setId(temp[0].toString());
                bean.setCode(temp[1].toString());
                bean.setDescription(temp[2].toString());
                bean.setType(temp[3].toString());
                if(temp[4]!=null){
                    bean.setParent_id(temp[4].toString());
                }
                listBean.add(bean);
            }
        }
        return listBean;
    }
    
    /**张璐2015-10-30
     * 用于添加新的故障信息
     * @param des--故障描述
     * @param fiveCode--本级代码
     * @param pid--父节点
     */
    @Override
    public void addNewTrouble(String des,String fiveCode,String pid,String id){
        StringBuffer sb=new StringBuffer(1000);
        sb.append("INSERT into EQM_TROUBLE_INFO VALUES('"+id+"','"+fiveCode+"','"+des+"',5,'"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"','"+pid+"')");
        eqmtroubleDaoI.updateBySql(sb.toString(), null);
    }
    
    /**
     * 删除新添加的故障
     * 张璐
     */
    @Override
    public void deleteNewTrouble(String id){
        StringBuffer sb=new StringBuffer(1000);
        sb.append("DELETE from EQM_TROUBLE_INFO where id='"+id+"' ");
        eqmtroubleDaoI.updateBySql(sb.toString(), null);
    }
 
    @Override
    public void dasSendTrouble(String ids) {
        ids=ids.replaceAll(",", "','");
        StringBuffer hqlbuffer=new StringBuffer(1000);
        hqlbuffer.append("from EqmTrouble where 1=1 and status=1 and id in ('"+ids+"')");
        List<EqmTrouble> eqmtlist=troubleDao.query(hqlbuffer.toString());//通过ids查询维修记录表
        hqlbuffer.setLength(0);
        hqlbuffer.append("from EqmFixRec where 1=1 and eqmtrouble_id in ('"+ids+"') ");//通过ids查询备品备件更换记录表
        List<EqmFixRec> eqmfrlist=eqmFixRecDao.query(hqlbuffer.toString());
        //调用封装XML方法
        try {
            WorkOrderStatChangeInterceptor.getInstance().dasSendEquipmentRepairRecord(eqmtlist,eqmfrlist);
        } catch (Exception e) {
            log.info("设备维修记录反馈异常!");
            e.printStackTrace();
        }
    }
 
    
}