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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
package com.shlanbao.tzsc.pms.sys.datadict.service.impl;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
import org.apache.poi.hssf.record.formula.functions.T;
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.SysEqpTypeDaoI;
import com.shlanbao.tzsc.base.mapping.CosSpareParts;
import com.shlanbao.tzsc.base.mapping.EqmLubricantMaintain;
import com.shlanbao.tzsc.base.mapping.EqmLubricantPlan;
import com.shlanbao.tzsc.base.mapping.MdEquipment;
import com.shlanbao.tzsc.base.mapping.SysEqpCategory;
import com.shlanbao.tzsc.base.mapping.SysEqpType;
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.plugin.service.LoadComboboxServiceI;
import com.shlanbao.tzsc.pms.equ.lubricate.beans.EqmBubricantfBean;
import com.shlanbao.tzsc.pms.sys.datadict.beans.SysEqpTypeBean;
import com.shlanbao.tzsc.pms.sys.datadict.service.SysEqpTypeServiceI;
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import com.shlanbao.tzsc.utils.tools.StringUtil;
 
/**
 * 数据字典实现类
 */
@Service
public class SysEqpTypeServiceImpl extends BaseService implements
        SysEqpTypeServiceI {
    @Autowired
    private SysEqpTypeDaoI sysEqpTypeDao;
    @Autowired
    private BaseDaoI<T> baseDao;
    @Autowired
    private LoadComboboxServiceI comboboxServiceI;
 
    // 更新 图片设置的点信息
    @Override
    public void addSetUpImages(String id, String imagePointMsg, String filePath)
            throws Exception {
        if (null != id && !"".equals(id)) {
            SysEqpType mdEqpType = sysEqpTypeDao.findById(SysEqpType.class, id);
            if (null != mdEqpType) {
                imagePointMsg = imagePointMsg.replaceAll("\"", "\'");// 双引号替换成单引号
                imagePointMsg = imagePointMsg.replaceAll(" ", "");
                mdEqpType.setSetImagePoint(imagePointMsg);
                if (null != filePath && !"".equals(filePath)) {
                    mdEqpType.setFilePath(filePath);
                } else {
                    if (null != mdEqpType.getSysEqpCategory()) {
                        /*
                         * if(null!=mdEqpType.getSysEqpCategory().getUploadBean()
                         * ){
                         * mdEqpType.setFilePath(mdEqpType.getSysEqpCategory()
                         * .getUploadBean().getFileId()); }
                         */
                    }
                }
            }
        }
    }
 
    @Override
    public void addMdType(SysEqpTypeBean mdEqpTypeBean) throws Exception {
        SysEqpType mdEqpType = new SysEqpType();
        if (StringUtil.notNull(mdEqpTypeBean.getId())) {
            mdEqpType = sysEqpTypeDao.findById(SysEqpType.class,
                    mdEqpTypeBean.getId());
            BeanConvertor.copyProperties(mdEqpTypeBean, mdEqpType);
        } else {// 保存
            mdEqpType = BeanConvertor.copyProperties(mdEqpTypeBean,
                    SysEqpType.class);
            mdEqpType.setId(UUID.randomUUID().toString());
        }
        if (StringUtil.notNull(mdEqpTypeBean.getCategoryId())) {
            mdEqpType.setSysEqpCategory(new SysEqpCategory(mdEqpTypeBean
                    .getCategoryId()));
        }
        if (StringUtil.notNull(mdEqpTypeBean.getOilId())) {// 润 滑 油(脂)ID
            EqmLubricantMaintain bean = new EqmLubricantMaintain();
            bean.setId(mdEqpTypeBean.getOilId());
            mdEqpType.setOilIdBean(bean);
        }
        if (StringUtil.notNull(mdEqpTypeBean.getFillUnit())) {// 加注量单位ID
            SysEqpType bean = new SysEqpType();
            bean.setId(mdEqpTypeBean.getFillUnit());
            mdEqpType.setFillUnitBean(bean);
        }
        if (StringUtil.notNull(mdEqpTypeBean.getFashion())) {// 方式ID
            SysEqpType bean = new SysEqpType();
            bean.setId(mdEqpTypeBean.getFashion());
            mdEqpType.setFashionBean(bean);
        }
        mdEqpType.setDel("0");
        if (StringUtil.notNull(mdEqpTypeBean.getId())) {
            // 更新不用写
        } else {
            sysEqpTypeDao.save(mdEqpType);
        }
        // comboboxServiceI.initCombobox(ComboboxType.EQPTYPE);
    }
 
    @Override
    public SysEqpTypeBean getTypeById(String id) throws Exception {
        SysEqpType mdEqpType = sysEqpTypeDao.findById(SysEqpType.class, id);
        SysEqpTypeBean bean = BeanConvertor.copyProperties(mdEqpType,
                SysEqpTypeBean.class);
        if (null != mdEqpType.getSysEqpCategory()) {
            bean.setCategoryId(mdEqpType.getSysEqpCategory().getId());
            bean.setCategoryName(mdEqpType.getSysEqpCategory().getName());
        }
        if (null != mdEqpType.getOilIdBean()) {// 润滑油
            bean.setOilId(mdEqpType.getOilIdBean().getId());
            bean.setOilName(mdEqpType.getOilIdBean().getLubricantName());
        }
        if (null != mdEqpType.getFillUnitBean()) {// 单位
            bean.setFillUnit(mdEqpType.getFillUnitBean().getId());
            bean.setFillUnitName(mdEqpType.getFillUnitBean().getName());
        }
        if (null != mdEqpType.getFashionBean()) {// 方式
            bean.setFashion(mdEqpType.getFashionBean().getId());
            bean.setFashionName(mdEqpType.getFashionBean().getName());
        }
        return bean;
    }
 
    @Override
    public DataGrid queryMdType(SysEqpTypeBean mdTypeBean, PageParams pageParams)
            throws Exception {
        String hql = "from SysEqpType o ";
        hql += " left join fetch  o.sysEqpCategory sys1  ";//
        hql += " left join fetch  o.oilIdBean sys2  "; // 润滑油
        hql += " left join fetch  o.fillUnitBean sys3  "; // 单位
        hql += " left join fetch  o.fashionBean sys4  "; // 方式
        hql += " where o.del=0  ";
        StringBuffer params = new StringBuffer();
        if (StringUtil.notNull(mdTypeBean.getName())) {
            params.append(" and o.name like '%" + mdTypeBean.getName() + "%'");
        }
        if (StringUtil.notNull(mdTypeBean.getCode())) {
            params.append(" and o.code like '%" + mdTypeBean.getCode() + "%'");
        }
        if (StringUtil.notNull(mdTypeBean.getCategoryId())) {
            params.append(" and o.sysEqpCategory.id='"
                    + mdTypeBean.getCategoryId() + "'");
        }
        if (StringUtil.notNull(mdTypeBean.getId())) {
            params.append(" and o.id='" + mdTypeBean.getId() + "'");
        }
        List<SysEqpType> rows = sysEqpTypeDao.queryByPage(
                hql.concat(params.toString()), pageParams);
        List<SysEqpTypeBean> beans = new ArrayList<SysEqpTypeBean>();
        for (SysEqpType mdEqpType : rows) {
            try {
                SysEqpTypeBean bean = new SysEqpTypeBean();
                beanConvertor.copyProperties(mdEqpType, bean);
                if (null != mdEqpType.getSysEqpCategory()) {
                    bean.setCategoryId(mdEqpType.getSysEqpCategory().getId());
                    bean.setCategoryName(mdEqpType.getSysEqpCategory().getName());
                }
                if (null != mdEqpType.getOilIdBean()) {// 润滑油
                    bean.setOilId(mdEqpType.getOilIdBean().getId());
                    bean.setOilName(mdEqpType.getOilIdBean().getLubricantName());
                }
                if (null != mdEqpType.getFillUnitBean()) {// 单位
                    bean.setFillUnit(mdEqpType.getFillUnitBean().getId());
                    bean.setFillUnitName(mdEqpType.getFillUnitBean().getName());
                }
                if (null != mdEqpType.getFashionBean()) {// 方式
                    bean.setFashion(mdEqpType.getFashionBean().getId());
                    bean.setFashionName(mdEqpType.getFashionBean().getName());
                }
                beans.add(bean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        hql = "select count(*) from SysEqpType o where o.del=0 ";
        long total = sysEqpTypeDao.queryTotal(hql.concat(params.toString()));
        return new DataGrid(beans, total);
    }
 
    @Override
    public void deleteMdType(String id) throws Exception {
        // sysEqpTypeDao.findById(SysEqpType.class, id).setDel("1");
        sysEqpTypeDao.deleteById(id, SysEqpType.class);
        // comboboxServiceI.initCombobox(ComboboxType.EQPTYPE);
    }
 
    @Override
    public List<SysEqpTypeBean> queryMdType() throws Exception {
        // String hql = "from SysEqpType o where 1=1 and o.del=0";
        String hql = "from SysEqpType o ";
        hql += " left join fetch  o.sysEqpCategory sys1  ";//
        hql += " left join fetch  o.oilIdBean sys2  "; // 润滑油
        hql += " left join fetch  o.fillUnitBean sys3  "; // 单位
        hql += " left join fetch  o.fashionBean sys4  "; // 方式
        hql += " where o.del=0  ";
        List<SysEqpType> eqpTypes = sysEqpTypeDao.query(hql, new Object[] {});
        List<SysEqpTypeBean> beans = new ArrayList<SysEqpTypeBean>();
        for (SysEqpType mdEqpType : eqpTypes) {
            SysEqpTypeBean bean = new SysEqpTypeBean();
            beanConvertor.copyProperties(mdEqpType, bean);
            if (null != mdEqpType.getSysEqpCategory()) {
                bean.setCategoryId(mdEqpType.getSysEqpCategory().getId());
                bean.setCategoryName(mdEqpType.getSysEqpCategory().getName());
            }
            if (null != mdEqpType.getOilIdBean()) {// 润滑油
                bean.setOilId(mdEqpType.getOilIdBean().getId());
                bean.setOilName(mdEqpType.getOilIdBean().getLubricantName());
            }
            if (null != mdEqpType.getFillUnitBean()) {// 单位
                bean.setFillUnit(mdEqpType.getFillUnitBean().getId());
                bean.setFillUnitName(mdEqpType.getFillUnitBean().getName());
            }
            if (null != mdEqpType.getFashionBean()) {// 方式
                bean.setFashion(mdEqpType.getFashionBean().getId());
                bean.setFashionName(mdEqpType.getFashionBean().getName());
            }
            beans.add(bean);
        }
        return beans;
    }
 
    @Override
    public List<SysEqpTypeBean> queryMdEqpTypeByCategory(String[] categoryIds)
            throws Exception {
        // String hql = "from SysEqpType o where 1=1 and o.del=0 ";
        String hql = "from SysEqpType o ";
        hql += " left join fetch  o.sysEqpCategory sys1  ";//
        hql += " left join fetch  o.oilIdBean sys2  "; // 润滑油
        hql += " left join fetch  o.fillUnitBean sys3  "; // 单位
        hql += " left join fetch  o.fashionBean sys4  "; // 方式
        hql += " where o.del=0  ";
        hql += " and o.sysEqpCategory.id in ("
                + StringUtil.arrayToStringBySqlin(categoryIds) + ") ";
        List<SysEqpType> eqpTypes = sysEqpTypeDao.query(hql);
        List<SysEqpTypeBean> beans = new ArrayList<SysEqpTypeBean>();
        for (SysEqpType mdEqpType : eqpTypes) {
            SysEqpTypeBean bean = new SysEqpTypeBean();
            beanConvertor.copyProperties(mdEqpType, bean);
            if (null != mdEqpType.getSysEqpCategory()) {
                bean.setCategoryId(mdEqpType.getSysEqpCategory().getId());
                bean.setCategoryName(mdEqpType.getSysEqpCategory().getName());
            }
            if (null != mdEqpType.getOilIdBean()) {// 润滑油
                bean.setOilId(mdEqpType.getOilIdBean().getId());
                bean.setOilName(mdEqpType.getOilIdBean().getLubricantName());
            }
            if (null != mdEqpType.getFillUnitBean()) {// 单位
                bean.setFillUnit(mdEqpType.getFillUnitBean().getId());
                bean.setFillUnitName(mdEqpType.getFillUnitBean().getName());
            }
            if (null != mdEqpType.getFashionBean()) {// 方式
                bean.setFashion(mdEqpType.getFashionBean().getId());
                bean.setFashionName(mdEqpType.getFashionBean().getName());
            }
            beans.add(bean);
        }
        return beans;
    }
 
    @Override
    public List<SysEqpType> queryBean(SysEqpTypeBean mdTypeBean) {
        String hql = "from SysEqpType o ";
        hql += " left join fetch  o.sysEqpCategory sys1  ";//
        hql += " left join fetch  o.oilIdBean sys2  "; // 润滑油
        hql += " left join fetch  o.fillUnitBean sys3  "; // 单位
        hql += " left join fetch  o.fashionBean sys4  "; // 方式
        hql += " where o.del=0  ";
        StringBuffer params = new StringBuffer();
        if (StringUtil.notNull(mdTypeBean.getName())) {
            params.append(" and o.name like '%" + mdTypeBean.getName() + "%'");
        }
        if (StringUtil.notNull(mdTypeBean.getCode())) {
            params.append(" and o.code like '%" + mdTypeBean.getCode() + "%'");
        }
        if (StringUtil.notNull(mdTypeBean.getCategoryId())) {
            params.append(" and o.sysEqpCategory.id='"
                    + mdTypeBean.getCategoryId() + "'");
        }
        if (StringUtil.notNull(mdTypeBean.getId())) {
            params.append(" and o.id='" + mdTypeBean.getId() + "'");
        }
        List<SysEqpType> rows = sysEqpTypeDao.query(hql.concat(params
                .toString()));
        return rows;
    }
 
    @Override
    public void inputExeclAndReadWrite(List<SysEqpTypeBean> lt,
            SysEqpTypeBean etb) throws Exception {
        for (int i = 0; i < lt.size(); i++) {
            SysEqpTypeBean etp = lt.get(i);
            if(etp.getName().trim().equals("")||etp.getDes().trim().equals("")){
                continue;
            }
            SysEqpType sysEqpType = new SysEqpType();
            SysEqpCategory c = new SysEqpCategory();
            c.setId(etb.getId());
            sysEqpType.setSysEqpCategory(c);
            sysEqpType.setDel("0");
            sysEqpType.setEnable(1L);
            sysEqpType.setCode(UUID.randomUUID().toString());
            // 判断是否已经存在
            String sql = "select cid from SYS_EQP_TYPE where cid='"
                    + etb.getId() + "' and name='" + etp.getName() + "'";
            List list = sysEqpTypeDao.queryBySql(sql);
            if (list != null && list.size() > 0) {
                continue;
            } else {
                beanConvertor.copyProperties(etp, sysEqpType);
                // 润滑油
                if (StringUtil.notNull(etp.getOilId())) {
                    EqmLubricantMaintain e = new EqmLubricantMaintain();
                    e.setId(etp.getOilId());
                    sysEqpType.setOilIdBean(e);
                }
                // 润滑油加注单位
                if (StringUtil.notNull(etp.getCategoryId())) {
                    SysEqpType e = new SysEqpType();
                    e.setId(etp.getCategoryId());
                    sysEqpType.setFillUnitBean(e);
                }
                // 润滑方式
                if (StringUtil.notNull(etp.getFashion())) {
                    SysEqpType e = new SysEqpType();
                    e.setId(etp.getFashion());
                    sysEqpType.setFashionBean(e);
                }
                if(StringUtil.notNull(etp.getPeriodUnit2())){
                    sysEqpType.setUnit_id(etp.getPeriodUnit2());
                }
                sysEqpTypeDao.save(sysEqpType);
            }
        }
 
    }
 
    /**
     * 功能说明:通过设备Id,日期时间,班次,润滑类型查找表eqm_lubricat_plan表
     * @author wanchanghuang
     * @time 2015年9月17日16:24:37
     * 
     * */
    @Override
    public EqmBubricantfBean queryEqmLubricantPlanByPar(
            EqmBubricantfBean bean,String date,String unit_id,String shift_id,String eqp_id) {
        String sql="select id,lub_id,shift_id from EQM_LUBRICAT_PLAN where  shift_id='"+shift_id+"' and CONVERT(varchar(50),date_p,23)='"+date+"' and lub_id='"+unit_id+"' and eqp_id='"+eqp_id+"' ";
        List<?> list=baseDao.queryBySql(sql);
         EqmBubricantfBean b=new EqmBubricantfBean();
         if(list.size()>0){
            Object[] temp=(Object[])list.get(0);
            try {
                b.setId(temp[0].toString());
                if(temp[1]!=null){
                    b.setLub_id(Integer.parseInt(temp[1].toString()));
                }
                b.setShift_id(temp[2].toString());
            } catch (Exception e) {
                // TODO: handle exception
            }
         }else{
             b=null;
         }
        return b;
    }
 
     /**
     * [功能说明]:根据sys_eqp_type表cid查询集合
     * @time 2015年9月24日9:19:51
     * @author wanchanghuang    
     * 
     * */
    @Override
    public List<SysEqpTypeBean> querySysEqmTypeByCid(SysEqpTypeBean sysEqpType) {
        List<SysEqpTypeBean> listSete=new ArrayList<SysEqpTypeBean>();
        String sql="SELECT a.id, a.name, a.des, (select lubricant_name from EQM_LUBRICANT_MAINTAIN where id=a.oilid) as oilid, a.fill_quantity, (select name from SYS_EQP_TYPE where id=a.fill_unit ) as fill_unit_name, (select name from SYS_EQP_TYPE where id=a.fashion  ) as fashion_name, a.period, a.unit_id FROM SYS_EQP_TYPE a WHERE a.del = 0 AND cid = '"+sysEqpType.getCategoryId()+"'";
        List<?> list=baseDao.queryBySql(sql);
        if(list.size()>0){
            for(Object o:list){
                SysEqpTypeBean st=new SysEqpTypeBean();
                Object[] temp=(Object[]) o;
                st.setId(temp[0].toString());
                st.setName(temp[1].toString());
                if(temp[2]!=null){
                    st.setDes(temp[2].toString());
                }
                if(temp[3]!=null){
                    st.setOilId(temp[3].toString());
                }
                if(temp[4]!=null){
                    st.setFillQuantity(temp[4].toString());
                }
                if(temp[5]!=null){
                    st.setFillUnitName(temp[5].toString());
                }
                if(temp[6]!=null){
                    st.setFashionName(temp[6].toString());
                }
                if(temp[7]!=null){
                    st.setPeriod(Integer.parseInt(temp[7].toString()));
                }
                if(temp[8]!=null){
                    st.setUnit_id(temp[8].toString());
                }
                
                listSete.add(st);
            }
        }
        return listSete;
    }
 
}