package com.ld.igds.view.service;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.models.Granary;
|
import com.ld.igds.util.ContextUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Component;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 基础信息-廒间信息
|
*
|
* @Author:YAN
|
*/
|
@Component
|
public class HGranaryService extends HibernateDao {
|
|
|
public void pageData(Page<Granary> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + Granary.class.getName()
|
+ " where companyId=:companyId";
|
if (null == param) {
|
param = new HashMap<>();
|
}
|
String companyId = (String) param.get("companyId");
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", companyId);
|
|
String str = (String) param.get("deptId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and deptId =:deptId";
|
args.put("deptId", str);
|
}
|
|
str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and ajmc like:name";
|
args.put("name", "%" + str + "%");
|
}
|
|
String count = "select count(*) " + hql;
|
hql += " order by updateTime desc";
|
|
this.pagingQuery(page, hql, count, args);
|
|
}
|
|
public String saveOrUpdate(Granary data) {
|
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getDeptId()) {
|
data.setDeptId(ContextUtil.subDeptId(null));
|
}
|
data.setCompanyId(ContextUtil.getCompanyId());
|
session.saveOrUpdate(data);
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public String delData(Granary data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
|
}
|