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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.shlanbao.tzsc.pms.equ.fix.service.impl;
 
import java.util.ArrayList;
import java.util.Date;
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.EqmFixRecDaoI;
import com.shlanbao.tzsc.base.mapping.EqmFixRec;
import com.shlanbao.tzsc.base.mapping.MdEquipment;
import com.shlanbao.tzsc.base.mapping.MdShift;
import com.shlanbao.tzsc.base.mapping.SysUser;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.base.model.SessionInfo;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.pms.equ.fix.beans.EqmFixRecBean;
import com.shlanbao.tzsc.pms.equ.fix.service.EqmFixRecServiceI;
 
@Service
public class EqmFixRecServiceImpl extends BaseService implements EqmFixRecServiceI{
    @Autowired
    protected EqmFixRecDaoI eqmFixDao;
 
    @Override
    public void addFixRec(EqmFixRecBean eqmFixRecBean) throws Exception {
        if(StringUtil.notNull(eqmFixRecBean.getId())){
            String hql = "from EqmFixRec  where id = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(eqmFixRecBean.getId());
            EqmFixRec fixRec = eqmFixDao.unique(EqmFixRec.class, hql, params);
            if(null!=fixRec){
                fixRec.setEqp_id(new MdEquipment(eqmFixRecBean.getEquipId()));//设备
                fixRec.setShift_id(new MdShift(eqmFixRecBean.getShiftId()));//班次
                //fixRec.setFixtype(eqmFixRecBean.getFixtype());//维修类型
                fixRec.setMaintaiin_type(new Long(eqmFixRecBean.getFixtype()).intValue());
                fixRec.setRemark(eqmFixRecBean.getRemark());//备注    
                if(null!=eqmFixRecBean.getAppointUsrId()&&!"".equals(eqmFixRecBean.getAppointUsrId())){
                    fixRec.setMaintaiin_id(eqmFixRecBean.getAppointUsrId());//维修人
                    fixRec.setStatus(2);//状态 新增是 0 或 空  , 运行是 1 ,完成 2 
                    fixRec.setCreate_user_time(new Date());//创建时间
                }
            }
        }else{
            //新增
            EqmFixRec fixRec = BeanConvertor.copyProperties(eqmFixRecBean, EqmFixRec.class ) ;
            fixRec.setAsk_date(new Date());//请求时间
            fixRec.setEqp_id(new MdEquipment(eqmFixRecBean.getEquipId()));//设备
            SessionInfo sessionInfo = (SessionInfo) WebContextUtil.getObjectFromSession();//设置请求用户
            fixRec.setAsk_userId(sessionInfo.getUser().getId());
            
            fixRec.setShift_id(new MdShift(eqmFixRecBean.getShiftId()));//班次
            //fixRec.setShift_id(eqmFixRecBean.getShiftId());
            //fixRec.setId(null);
            fixRec.setStatus(0);//状态 新增是 0 或 空  , 运行是 1 ,完成 2 
            if(null!=eqmFixRecBean.getAppointUsrId()&&!"".equals(eqmFixRecBean.getAppointUsrId())){
                fixRec.setMaintaiin_id(eqmFixRecBean.getAppointUsrId());
                fixRec.setMaintaiin_time(new Date());
            }
            eqmFixDao.save(fixRec);
        }
        //eqmFixDao.saveOrUpdate(fixRec);
    }
 
    @Override
    
    public EqmFixRecBean getFixRecById(String id) throws Exception {
        EqmFixRec fixRec=  eqmFixDao.findById(EqmFixRec.class,id);
        EqmFixRecBean recBean=BeanConvertor.copyProperties(fixRec, EqmFixRecBean.class);
        MdEquipment mdEquipment=fixRec.getEqp_id();
        recBean.setEquipId(mdEquipment.getId());
        recBean.setEquipName(mdEquipment.getEquipmentName());
        MdShift shift=fixRec.getShift_id();
        recBean.setShiftId(shift.getId());
        recBean.setShiftName(shift.getName());
        if(null!=fixRec.getMaintaiin_id()){
//            recBean.setAppointUsrId(fixRec.getAppointUsr().getId());
//            recBean.setAppointUsrName(fixRec.getAppointUsr().getName());
            recBean.setAppointUsrId(fixRec.getMaintaiin_id());
            recBean.setAppointUsrName(fixRec.getMaintaiin_name());
        }
         return recBean;
    }
/**
 * 备件跟换记录查询
 * 2015-09-30
 * shisihai
 */
    @Override
    public DataGrid queryFixRec(EqmFixRecBean eqmFixRecBean, PageParams pageParams)throws Exception {
        int page=pageParams.getPage();
        int row=pageParams.getRows();
        Integer leng=0;
        StringBuffer count=this.getSql(eqmFixRecBean, 0);
        List<?> l=eqmFixDao.queryBySql(count.toString());
        if(l!=null && l.size()>0){
            leng=Integer.parseInt( l.get(0).toString()) ;
        }
        StringBuffer sb=this.getSql(eqmFixRecBean, 1);
        sb.append(" and t.rownumberf > " +(page-1)*row);
        sb.append(" and t.rownumberf <= " +page*row);
        List<Object[]> ls=(List<Object[]>) eqmFixDao.queryBySql(sb.toString());
        List<EqmFixRecBean> beans=new ArrayList<EqmFixRecBean>();
        EqmFixRecBean bean =null;
        for (Object[] o : ls) {
            try {
                bean=new EqmFixRecBean();
                if(o[1]!=null){
                    bean.setId(o[1].toString());
                }
                if(o[2]!=null||o[10]!=null){
                    bean.setEquipName(o[2]==null?o[10].toString():o[2].toString());
                }
                if(o[3]!=null||o[11]!=null){
                    bean.setShiftName(o[3]==null?o[11].toString():o[3].toString());
                }
                if(o[4]!=null){
                    bean.setBjName(o[4].toString());
                }
                if(o[5]!=null){
                    bean.setBjCode(o[5].toString());
                }
                if(o[6]!=null){
                    bean.setBjNum(o[6].toString());
                }
                if(o[7]!=null){
                    bean.setFixtim(o[7].toString());
                }
                if(o[8]!=null){
                    bean.setGhName(o[8].toString());
                }
                if(o[9]!=null){
                    bean.setFixtype(Long.parseLong(o[9].toString()));//更换备件的来源 1-点检   2-维修呼叫   3-轮保   4-备品备件 5、检修
                }
                beans.add(bean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        return new DataGrid(beans, (long)leng);
    }
 
    @LogAnno(operateType = "删除备品备件更换记录")
    @Override
    public void deleteFixRec(String id) throws Exception {
        List list = new ArrayList<>();
        list.add(id);
        eqmFixDao.updateBySql("delete from EQP_SPARE_PARTS where id = ?",list);
    }
    @LogAnno(operateType = "批量删除备品备件更换记录")
    @Override
    public void batchDeleteFixRec(String ids) {
        String[] split = ids.split(",");
        try {
            for (int i = 0; i < split.length; i++) {
                List list = new ArrayList<>();
                list.add(split[i]);
                eqmFixDao.updateBySql("delete from EQP_SPARE_PARTS where id = ?",list);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
    /**
 * 
 * @param eqmFixRecBean
 * @param type 1 查信息  其余查条数
 * @return
 */
    private StringBuffer getSql(EqmFixRecBean eqmFixRecBean,int type){
        StringBuffer sb=null;
        if(type==1){
            sb=new StringBuffer(" SELECT * from ");
        }else{
             sb=new StringBuffer(" select count(0) from ");
        }
        sb.append("(select rownum as rownumberf, a.id,d.equipment_name,e.name,"
                +" a.SPARE_PARTS_NAME,a.SPARE_PARTS_CODE,a.SPARE_PARTS_NUM,"
                +" a.REPAIR_DATE,a.MAINTAIIN_NAME,b.type,b.eqp_name,b.shift_name"
                +" from EQP_SPARE_PARTS a "
                +" LEFT JOIN EQM_WHEEL_COVEL_PLAN b ON A .EWCP_ID = b.ID"
                +" left join EQP_REQUEST_RECORD f on a.eqp_rr_id = f.id "
                +" LEFT JOIN MD_EQUIPMENT D ON f.eqp_id = D.ID"
                +" LEFT JOIN MD_SHIFT E ON f.shift = E.ID where 1=1 ");
        
        
    
        if(StringUtil.notNull(eqmFixRecBean.getReqtim())){
            sb.append(" and to_char(a.REPAIR_DATE,'yyyy-MM-dd') >='" +eqmFixRecBean.getReqtim()+ "'");
        }
        //完成时间2
        if(StringUtil.notNull(eqmFixRecBean.getRestim())){
            sb.append(" and to_char(a.REPAIR_DATE,'yyyy-MM-dd') <= '" +eqmFixRecBean.getRestim()+ "'");
        }
        
        //设备id
        if(StringUtil.notNull(eqmFixRecBean.getEquipId())){
            sb.append( " and d.id= '" +eqmFixRecBean.getEquipId()+ "'");
        }
        //班次
        if(StringUtil.notNull(eqmFixRecBean.getShiftId())){
            sb.append(" and e.id='" +eqmFixRecBean.getShiftId()+ "'");
        }
        /*//维修类型 0  电器和 机械 1
        if(eqmFixRecBean.getFixtype()!=null){
            sb.append( " and b.TYPE=" +eqmFixRecBean.getFixtype());
        }*/
        sb.append(" order by a.REPAIR_DATE ) t where 1=1 ");
        return sb;
    }
    
}