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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package com.shlanbao.tzsc.pms.equ.lubricate.service.impl;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.shlanbao.tzsc.utils.tools.LogAnno;
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.EqmLubricantDaoI;
import com.shlanbao.tzsc.base.mapping.EqmLubricant;
import com.shlanbao.tzsc.base.mapping.EqmLubricantPlan;
import com.shlanbao.tzsc.base.mapping.EqpLubricantRecord;
import com.shlanbao.tzsc.base.mapping.MdEqpCategory;
import com.shlanbao.tzsc.base.mapping.MdEqpType;
import com.shlanbao.tzsc.base.mapping.MdEquipment;
import com.shlanbao.tzsc.base.mapping.SchStatInput;
import com.shlanbao.tzsc.base.mapping.SysEqpCategory;
import com.shlanbao.tzsc.base.mapping.SysEqpType;
import com.shlanbao.tzsc.base.mapping.SysRole;
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.service.BaseService;
import com.shlanbao.tzsc.pms.equ.fix.beans.EqmFixRecBean;
import com.shlanbao.tzsc.pms.equ.lubricate.beans.EqmLubricantBean;
import com.shlanbao.tzsc.pms.equ.lubricate.service.EqmLubricantServiceI;
import com.shlanbao.tzsc.pms.sch.stat.beans.InputBean;
import com.shlanbao.tzsc.pms.sys.datadict.beans.SysEqpTypeBean;
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import com.shlanbao.tzsc.utils.tools.DateUtil;
import com.shlanbao.tzsc.utils.tools.StringUtil;
@Service
public class EqmLubricantServiceImpl extends BaseService implements EqmLubricantServiceI {
    @Autowired
    private EqmLubricantDaoI lubricantDao;
    @Autowired
    private BaseDaoI<Object> baseDao;
    //新增
    @LogAnno(operateType = "新增设备润滑数据明细")
    @Override
    public boolean addBean(EqmLubricant bean) {
        lubricantDao.save(bean);
        return true;
    }
    
    //根据Id获取对象
    @Override
    public EqmLubricant getBeanById(String id){
        return lubricantDao.findById(EqmLubricant.class, id);
    }
    //根据Id获取对象
    @Override
    public EqmLubricantBean getBeanByIds(String id) throws Exception{
        
        EqmLubricant qmLubricant=lubricantDao.findById(EqmLubricant.class, id);
        EqmLubricantBean bean=BeanConvertor.copyProperties(qmLubricant, EqmLubricantBean.class);
        bean.setCategoryId(qmLubricant.getSysEqpCategory().getId());
        bean.setCategoryName(qmLubricant.getSysEqpCategory().getName());
        return bean;
    }
    //修改
    @LogAnno(operateType = "修改设备润滑数据明细")
    @Override
    public boolean updateBean(EqmLubricantBean bean) {
        EqmLubricant o = lubricantDao.findById(EqmLubricant.class, bean.getId());
        o.setNum(bean.getNum());
        o.setEquLocation(bean.getEquLocation());
        o.setEnable(bean.getEnable());
        o.setLubPosition(bean.getLubPosition());
        o.setFixedPoints(bean.getFixedPoints());
        o.setLubOil(bean.getLubOil());
        o.setLubMethod(bean.getLubMethod());
        o.setChangeOilDosage(bean.getChangeOilDosage());
        o.setChangeOilCycle(bean.getChangeOilCycle());
        o.setSpePerson(bean.getSpePerson());
        o.setRoleId(bean.getRoleId());
        o.setQuaQuantity(bean.getQuaQuantity());
        o.setQuaUnit(bean.getQuaUnit());
        o.setDes(bean.getDes());
        o.setRoleId(bean.getRoleId());
        o.setLastUpdateName(bean.getLastUpdateName());
        o.setLastUpdateTime(bean.getLastUpdateTime());
        o.setShiftId(bean.getShiftId());
        return lubricantDao.saveOrUpdate(o);
    }
 
    //查询
    @Override
    public DataGrid searchBean(EqmLubricantBean seachBean,PageParams pageParams) {
        StringBuffer hql=new StringBuffer();
        hql.append("select o.id,o.name,");
        hql.append("o.eqp_type.id,");
        hql.append("o.eqp_type.name,");
        hql.append("o.create_usr.id ,");
        hql.append("o.create_usr.name ,");
        hql.append("o.cycle,");//周期
        hql.append("o.last_time,");
        hql.append("o.next_time,");
        hql.append("o.create_time,");
        hql.append("o.rule_id,");
        hql.append("o.rule_name,");
        hql.append("o.status, ");
        hql.append("o.eqp_category.id ");
        hql.append("from EqmLubricant o where 1=1 ");
        if(StringUtil.notNull(seachBean.getId())){
            hql.append("and o.id='"+seachBean.getId()+"' ");
        }
        
        /*if(StringUtil.notNull(seachBean.getEqp_typeId())){
            hql.append("and o.eqp_type.id='"+seachBean.getEqp_typeId()+"' ");
        }
        
        if(seachBean.getStatus()>-1){
            hql.append("and o.status='"+seachBean.getStatus()+"' ");
        }*/
        long total=baseDao.query(hql.toString()).size();
        //hql.append("order by o.date_p,o.shift.code ");
        List<Object> list=baseDao.queryByPage(hql.toString(), pageParams);
        List<EqmLubricantBean> returnList=new ArrayList<EqmLubricantBean>();
        for(Object o:list){
            Object[] temp=(Object[]) o;
            EqmLubricantBean b=new EqmLubricantBean();
            b.setId(temp[0].toString());
            /*b.setName(temp[1].toString());
            b.setEqp_typeId(temp[2].toString());
            b.setEqp_typeName(temp[3].toString());
            b.setCreate_uId(temp[4].toString());
            b.setCreate_uName(temp[5].toString());
            b.setCycle(Integer.parseInt(temp[6].toString()));
            if(temp[7]!=null)b.setLast_time(temp[7].toString());
            if(temp[8]!=null)b.setNext_time(temp[8].toString());
            if(temp[9]!=null)b.setCreate_time(temp[9].toString());
            b.setRuleId(temp[10].toString());
            if(temp[11]!=null)
                b.setRuleName(temp[11].toString());
            b.setStatus(Integer.parseInt(temp[12].toString()));
            b.setEqp_category(temp[13].toString());
            returnList.add(b);*/
        }
        return new DataGrid(returnList,total);
    }
    //生产润滑计划
    public void createLubricantPlan(String lubriId,String eqpId){
        EqmLubricant  lubri=getBeanById(lubriId);
        EqmLubricantPlan plan=new EqmLubricantPlan();
        plan.setDate_p(new Date());
        plan.setEqp(new MdEquipment(eqpId));
        /*plan.setLub_id(lubri.getRule_id());*/
        plan.setStatus(0);
        
    }
    @Override
    public List<?> getListBySql(String sql){
        return baseDao.queryBySql(sql);
    }
 
    /**
     * [功能说明]:通过ID,查询润滑详细
     * @date 2017年8月30日11:28:42
     * @author wanchanghuang
     * */
    @Override
    public DataGrid queryEqmLubricationById(SysEqpCategory bean,
            PageParams pageParams) {
        List<EqmLubricantBean> beans = new ArrayList<EqmLubricantBean>();
        StringBuffer sb=new StringBuffer();
        long total=0;
        sb.append(" select a.ID,a.NUM,a.EQU_LOCATION,a.LUB_POSITION,a.FIXED_POINTS,a.LUB_OIL,a.LUB_METHOD,a.CHANGE_OILDOSAGE,a.CHANGE_OILCYCLE, ");
        sb.append(" a.SPE_PERSON,a.QUA_QUANTITY,a.QUA_UNIT,a.DES,a.CREATE_TIME,a.LAST_UPDATE_NAME,b.id as SYS_EC,a.role_id,a.ENABLE,a.SHIFT_ID,a.LAST_UPDATE_TIME from EQM_LUBRICATION a,SYS_EQP_CATEGORY b ");
        sb.append(" where b.maintainace_type='"+bean.getMaintainaceType()+"' and b.id='"+bean.getId()+"' and a.SYS_EC=b.id ");
        if(StringUtil.notEmpty(bean.getCode())&&!"4".equals(bean.getCode())){
            sb.append(" and a.SHIFT_ID ="+StringUtil.convert2Integer(bean.getCode())+"");
        }
        if (StringUtil.notEmpty(bean.getLubPosition())) {
            sb.append(" and a.lub_position like '%"+bean.getLubPosition()+"%'");
        }
        if (StringUtil.notEmpty(bean.getEquLocation())) {
            sb.append(" and a.equ_location like '%"+bean.getEquLocation()+"%'");
        }
        if(StringUtil.notNull(bean.getEqpType())){
            sb.append(" and b.name like '%"+bean.getEqpType()+"%'");
        }
        if(StringUtil.notNull(bean.getCycleType())){
            sb.append(" and b.cycle_type='"+bean.getCycleType()+"' ");
        }
        sb.append(" order by a.num asc ");
        List<?> list= lubricantDao.queryBySql(sb.toString());
        if(list!=null && list.size()>0){
            EqmLubricantBean eb=null;
            for(Object o:list){
                Object[] temp=(Object[]) o;
                eb=new EqmLubricantBean();
                eb.setId(StringUtil.convertObjToString(temp[0]));
                eb.setNum(StringUtil.convertObjToString(temp[1]));
                eb.setEquLocation(StringUtil.convertObjToString(temp[2]));
                eb.setLubPosition(StringUtil.convertObjToString(temp[3]));
                eb.setFixedPoints(StringUtil.convertObjToString(temp[4]));
                eb.setLubOil(StringUtil.convertObjToString(temp[5]));
                eb.setLubMethod(StringUtil.convertObjToString(temp[6]));
                eb.setChangeOilDosage(StringUtil.convertObjToString(temp[7]));
                eb.setChangeOilCycle(StringUtil.convertObjToString(temp[8]));
                eb.setSpePerson(StringUtil.convertObjToString(temp[9]));
                eb.setQuaQuantity(StringUtil.convertObjToString(temp[10]));
                eb.setQuaUnit(StringUtil.convertObjToString(temp[11]));
                eb.setDes(StringUtil.convertObjToString(temp[12]));
                eb.setCreateTime(DateUtil.formatStringToDate(temp[13].toString(), "yyyy-MM-dd HH:mm:ss"));
                eb.setLastUpdateName(StringUtil.convertObjToString(temp[14]));
                eb.setCategoryId(StringUtil.convertObjToString(temp[15]));
                eb.setRoleId(StringUtil.convertObjToString(temp[16]));
                eb.setEnable(StringUtil.convertObjToString(temp[17]));
                eb.setShiftId(StringUtil.convert2Integer(temp[18]));
                eb.setLastUpdateTime(temp[19]==null?null:DateUtil.formatStringToDate(temp[19].toString(), "yyyy-MM-dd HH:mm:ss"));
                beans.add(eb);
            }
        }
        return new DataGrid(beans, total);
    }
 
    @Override
    public List<SysRole> getRoleAll() {
        try {
            String sql="select id,name from SYS_ROLE where del=0";
            List<?> list=baseDao.queryBySql(sql);
            List<SysRole> srlist=new ArrayList<SysRole>();
            if(list!=null && list.size()>0){
                SysRole sr=null;
                for(Object o:list){
                    Object[] temp=(Object[]) o;
                    sr=new SysRole();
                    sr.setId(StringUtil.convertObjToString(temp[0]));
                    sr.setName(StringUtil.convertObjToString(temp[1]));
                    srlist.add(sr);
                }
            }
            return srlist;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    @LogAnno(operateType = "删除设备润滑数据明细")
    @Override
    public void deleteLubrCycle(String id) {
        // sysEqpTypeDao.findById(SysEqpType.class, id).setDel("1");
        lubricantDao.deleteById(id, EqmLubricant.class);
        //.deleteById(id, SysEqpType.class);
                // comboboxServiceI.initCombobox(ComboboxType.EQPTYPE);
        
    }
 
    @Override
    public DataGrid queryLubricantRec(EqpLubricantRecord eqmFixRecBean, PageParams pageParams) {
        int page=pageParams.getPage();
        int row=pageParams.getRows();
        Integer leng=0;
        StringBuffer count=this.getSql(eqmFixRecBean, 0);
        List<?> l=lubricantDao.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[]>) lubricantDao.queryBySql(sb.toString());
        List<EqpLubricantRecord> beans=new ArrayList<EqpLubricantRecord>();
        EqpLubricantRecord bean =null;
        for (Object[] o : ls) {
            try {
                bean=new EqpLubricantRecord();
                if(o[1]!=null){
                    bean.setId(o[1].toString());
                }
                if(o[2]!=null){
                    bean.setGreaser(o[2].toString());
                }
                if(o[3]!=null){
                    bean.setLubricantName(o[3].toString());
                }
                if(o[4]!=null){
                    bean.setLubricantCode(o[4].toString());
                }
                if(o[5]!=null){
                    bean.setLubricantCount(o[5].toString());
                }
                if(o[6]!=null){
                    bean.setCreateTime_(o[6].toString());
                }
                if(o[7]!=null){
                    bean.setLubricantTime_(o[7].toString());
                }
                if(o[8]!=null){
                    bean.setEqp(o[8].toString());
                }
                if(o[9]!=null){
                    bean.setShift(o[9].toString());
                }
                beans.add(bean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        return new DataGrid(beans, (long)leng);
    }
 
    @Override
    public void batchDeleteLubrCycle(String ids) {
        String[] split = ids.split(",");
        try {
            for (int i = 0; i < split.length; i++) {
                lubricantDao.deleteById(split[i], EqmLubricant.class);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
 
    }
 
 
    private StringBuffer getSql(EqpLubricantRecord 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,a.greaser,a.LUBRICANT_NAME,a.LUBRICANT_CODE,"
                +" a.LUBRICANT_COUNT,a.CREATE_TIME,a.LUBRICANT_TIME,b.EQP_NAME,"
                +" b.SHIFT_NAME from EQP_LUBRICANT_RECORD a join EQM_WHEEL_COVEL_PLAN b"
                +" on a.EWCP_ID = b.id where 1=1");
        
        
    
        if(StringUtil.notNull(eqmFixRecBean.getLubricantTime_())){
            sb.append(" and to_char(a.LUBRICANT_TIME,'yyyy-MM-dd') >='" +eqmFixRecBean.getLubricantTime_()+ "'");
        }
        //完成时间2
        if(StringUtil.notNull(eqmFixRecBean.getCreateTime_())){
            sb.append(" and to_char(a.LUBRICANT_TIME,'yyyy-MM-dd') <= '" +eqmFixRecBean.getCreateTime_()+ "'");
        }
        
        //设备id
        if(StringUtil.notNull(eqmFixRecBean.getEqp())){
            sb.append( " and b.EQP_ID= '" +eqmFixRecBean.getEqp()+ "'");
        }
        //班次
        if(StringUtil.notNull(eqmFixRecBean.getShift())){
            sb.append(" and b.SHIFT_ID='" +eqmFixRecBean.getShift()+ "'");
        }
        /*//维修类型 0  电器和 机械 1
        if(eqmFixRecBean.getFixtype()!=null){
            sb.append( " and b.TYPE=" +eqmFixRecBean.getFixtype());
        }*/
        sb.append(" order by a.LUBRICANT_TIME ) t where 1=1 ");
        return sb;
    }
    
 
}