package com.ld.igds.pest.service;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import com.ld.igds.models.Gas;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Repository;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.models.Pest;
|
import com.ld.igds.pest.dto.PestData;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
|
/**
|
*
|
* @author: andy.jia
|
* @description:
|
* @version:
|
* @data:2020年1月16日
|
*
|
*/
|
@Repository
|
public class HPestDataService extends HibernateDao {
|
|
public void getDataReport(Page<PestData> page, Map<String, Object> parameter)
|
throws Exception {
|
if (null == parameter) {
|
parameter = new HashMap<String, Object>();
|
}
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
|
// 默认获取6个月的数据信息
|
Date date = (Date) parameter.get("start");
|
if (null == date) {
|
date = DateUtils.addMonths(new Date(), -6);
|
}
|
|
String hql = " from " + Pest.class.getName()
|
+ " where companyId=:companyId";
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
String arg = (String) parameter.get("depotId");
|
if (StringUtils.isNotEmpty(arg)) {
|
hql += " and depotId = :depotId";
|
args.put("depotId", arg);
|
}
|
|
if (null != date) {
|
hql += " and receiveDate >=:start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
|
date = (Date) parameter.get("end");
|
if (null != date) {
|
hql += " and receiveDate < :end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
|
String countHql = "select count(*) " + hql;
|
hql += " order by receiveDate desc";
|
|
this.pagingQuery(page, hql, countHql, args);
|
}
|
|
|
|
public void pageData(Page<Pest> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + Pest.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
|
String str = (String) param.get("depotId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and depotId =:depotId";
|
args.put("depotId", str);
|
}
|
|
}
|
String count = "select count(*) " + hql;
|
hql += " order by receiveDate desc";
|
this.pagingQuery(page, hql, count, args);
|
|
}
|
|
public void saveData(Pest data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (null == data.getBatchId()) {
|
data.setBatchId(DateFormatUtils.format(data.getReceiveDate(), "yyyyMMddHHmm"));
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
session.save(data);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
public String delData(Pest data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getBatchId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
}
|