YYC
2023-09-07 7243e0b4bd9a267a633d2e481e17646509b6868d
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
package com.ld.igds.n2.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.ld.igds.n2.dto.N2MacData;
import com.ld.igds.util.NumberUtil;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.models.N2MacConf;
import com.ld.igds.util.ContextUtil;
 
@Component
public class HMacConfService extends HibernateDao {
 
    public List<N2MacConf> getConfData(String companyId, String deptId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        String hql = " from " + N2MacConf.class.getName()
                + " where companyId=:companyId ";
 
        Map<String, Object> args = new HashMap<>();
        args.put("companyId", companyId);
 
        if (null != deptId) {
            hql += " and deptId=:deptId ";
            args.put("deptId", deptId);
        }
 
        hql += " order by sn";
 
        return this.query(hql, args);
    }
 
    public String saveData(N2MacConf data) {
        Session session = this.getSessionFactory().openSession();
        try {
            if (null == data.getDeptId()) {
                data.setDeptId(ContextUtil.subDeptId(null));
            }
            if (null == data.getCompanyId()) {
                data.setCompanyId(ContextUtil.getCompanyId());
            }
 
            if (null != data.getPurity() && data.getPurity() > 0) {
                data.setPurity(NumberUtil.keepPrecision(data.getPurity(), 2));
            }
 
            if (null != data.getFlow() &&data.getFlow() > 0) {
                data.setFlow(NumberUtil.keepPrecision(data.getFlow(), 2));
            }
 
            if (null != data.getPressure() &&data.getPressure() > 0) {
                data.setPressure(NumberUtil.keepPrecision(data.getPressure(), 2));
            }
 
            if (StringUtils.isEmpty(data.getId())) {
                data.setId(ContextUtil.getCurTimeMillis());
                if (null == data.getSn()) {
                    data.setSn(data.getId());
                }
                session.save(data);
            } else {
                if (null == data.getSn()) {
                    data.setSn(data.getId());
                }
                session.update(data);
            }
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
 
    public String delData(N2MacConf data) {
        Session session = this.getSessionFactory().openSession();
        try {
            session.delete(data);
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
 
    public N2MacConf getDataBySn(String sn) {
        if (null == sn)
            return null;
        String hql = " from " + N2MacConf.class.getName() + " where sn=:sn ";
 
        Map<String, Object> args = new HashMap<>();
        args.put("sn", sn);
 
        List<N2MacConf> list = this.query(hql, args);
 
        if (null == list || list.isEmpty())
            return null;
 
        return list.get(0);
    }
 
    public void updateMac(N2MacData data) {
        N2MacConf conf = new N2MacConf();
        BeanUtils.copyProperties(data, conf);
 
        Session session = this.getSessionFactory().openSession();
        try {
            session.update(conf);
        } finally {
            session.flush();
            session.close();
        }
    }
}