package com.ld.igds.quantity.service;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.ld.igds.models.QuantityConf;
|
import com.ld.igds.util.ContextUtil;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.hibernate.Session;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
public class HQuantityConfService extends HibernateDao {
|
|
@Autowired
|
private CoreQuantityService coreQuantityService;
|
|
|
public List<QuantityConf> getConfList(String companyId, String deptId) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
if (StringUtils.isEmpty(deptId)) {
|
deptId = ContextUtil.subDeptId(null);
|
}
|
|
String hql = " from " + QuantityConf.class.getName()
|
+ " where companyId=:companyId and deptId=:deptId order by depotId + 0 ";
|
|
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
parameterMap.put("companyId", companyId);
|
parameterMap.put("deptId", deptId);
|
|
List<QuantityConf> list = this.query(hql, parameterMap);
|
|
return list;
|
}
|
|
private List<QuantityConf> getAll() {
|
String hql = " from " + QuantityConf.class.getName();
|
return this.query(hql);
|
}
|
|
public void saveConf(QuantityConf conf) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (StringUtils.isEmpty(conf.getCompanyId())) {
|
conf.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(conf.getDeptId())) {
|
conf.setDeptId(ContextUtil.subDeptId(null));
|
}
|
//conf.setUpdateUser(ContextUtil.getLoginUserCName());
|
|
session.saveOrUpdate(conf);
|
|
flushConfCache(conf.getCompanyId(), conf.getDeptId());
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delQuantityConf(QuantityConf conf) {
|
|
if (null == conf.getCompanyId())
|
return null;
|
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(conf);
|
} finally {
|
session.flush();
|
session.close();
|
}
|
|
flushConfCache(conf.getCompanyId(), conf.getDeptId());
|
return null;
|
}
|
|
public void flushConfCache(String companyId, String deptId) {
|
|
List<QuantityConf> list = getAll();
|
|
coreQuantityService.setCacheQuantityConf(list);
|
}
|
|
|
}
|