package com.ld.igds.view.service;
|
|
import com.bstek.bdf2.core.business.IUser;
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.models.DepotStore;
|
import com.ld.igds.util.ContextUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Component
|
public class HDepotStoreService extends HibernateDao {
|
|
public void listDepotStore(Page<DepotStore> page, Map<String, Object> param) throws Exception {
|
String hql = " from " + DepotStore.class.getName()
|
+ " where companyId =:companyId and deptId =:deptId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
args.put("deptId", ContextUtil.subDeptId(null));
|
|
if (param != null) {
|
String str = (String) param.get("foodVariety");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and foodVariety =:foodVariety";
|
args.put("foodVariety", str);
|
}
|
|
str = (String) param.get("foodType");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and foodType =:foodType";
|
args.put("foodType", str);
|
}
|
|
str = (String) param.get("foodLevel");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and foodLevel =:foodLevel";
|
args.put("foodLevel", str);
|
}
|
}
|
|
String countHql = " select count(*) " + hql;
|
|
hql += " order by updateDate desc";
|
|
this.pagingQuery(page, hql, countHql, args);
|
}
|
|
public void saveDepotStore(DepotStore data) {
|
|
IUser user = ContextUtil.getLoginUser();
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
data.setUpdateDate(new Date());
|
|
if (StringUtils.isEmpty(data.getCompanyId())) {
|
data.setCompanyId(user.getCompanyId());
|
}
|
if (StringUtils.isEmpty(data.getDeptId())) {
|
data.setDeptId(ContextUtil.subDeptId(user));
|
}
|
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (StringUtils.isEmpty(data.getId())) {
|
data.setId(ContextUtil.getUUID());
|
data.setCreateDate(new Date());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delDepotStore(DepotStore data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.delete(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
}
|