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();
|
}
|
}
|
}
|