package com.ld.igds.inout.service;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.inout.InoutConstant;
|
import com.ld.igds.inout.dto.InoutParam;
|
import com.ld.igds.models.InoutRecord;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.hibernate.Query;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Component;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.models.InoutSettle;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
|
@Component
|
public class HInoutSettleService extends HibernateDao {
|
|
|
public void pageIoutRecord(Page<InoutRecord> page, InoutParam param) throws Exception {
|
String hql = " from " + InoutRecord.class.getName()
|
+ " where companyId =:companyId and progress =:progress";
|
Map<String, Object> args = new HashMap<String, Object>();
|
|
args.put("companyId", ContextUtil.getCompanyId());
|
args.put("progress", InoutConstant.PROGRESS_RECORD);
|
|
if (StringUtils.isNotEmpty(param.getType())) {
|
hql += " and type =:type";
|
args.put("type", param.getType());
|
}
|
|
if (StringUtils.isNotEmpty(param.getId())) {
|
hql += " and id like:id";
|
args.put("id", "%" + param.getId() + "%");
|
}
|
|
if (StringUtils.isNotEmpty(param.getPlateNum())) {
|
hql += " and plateNum like:plateNum";
|
args.put("plateNum", "%" + param.getPlateNum() + "%");
|
}
|
|
if (StringUtils.isNotEmpty(param.getCustomerId())) {
|
hql += " and customerId =:customerId";
|
args.put("customerId", param.getCustomerId());
|
}
|
|
if (StringUtils.isNotEmpty(param.getDepotId())) {
|
hql += " and depotId =:depotId";
|
args.put("depotId", param.getDepotId());
|
}
|
|
if (StringUtils.isNotEmpty(param.getFoodVariety())) {
|
hql += " and foodVariety =:foodVariety";
|
args.put("foodVariety", param.getFoodVariety());
|
}
|
|
if (StringUtils.isNotEmpty(param.getSettleTag())) {
|
hql += " and settleTag =:settleTag";
|
args.put("settleTag", param.getSettleTag());
|
}
|
|
if (null != param.getStart()) {
|
hql += " and completeTime >=:start";
|
args.put("start", DateUtil.getCurZero(param.getStart()));
|
}
|
|
if (null != param.getEnd()) {
|
hql += " and completeTime <=:end";
|
args.put("end", DateUtil.getNextZero(param.getEnd()));
|
}
|
|
hql += " and RECORD_STATUS_ <> 'ERROR' and RECORD_STATUS_ <> 'DEL'";
|
|
String countHql = " select count(*) " + hql;
|
|
hql += " order by id desc ";
|
|
this.pagingQuery(page, hql, countHql, args);
|
}
|
|
public InoutSettle getSettleById(String companyId, String id) {
|
String hql = " from " + InoutSettle.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
args.put("companyId", ContextUtil.getCompanyId());
|
if (StringUtils.isNotEmpty(id)) {
|
hql += " and id=:id";
|
args.put("id", id);
|
}
|
|
hql += " order by payTime desc";
|
List<InoutSettle> list = this.query(hql, args);
|
if (list != null && list.size() > 0) {
|
return list.get(0);
|
}
|
return null;
|
}
|
|
|
public String saveOrUpdateData(InoutSettle data) {
|
Session session = this.getSessionFactory().openSession();
|
|
try {
|
if(null == data.getPayTime()){
|
data.setPayTime(new Date());
|
}
|
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void updateInoutRecordPay(String id) {
|
String hql = " update "+InoutRecord.class.getName() +" set settleTag=:settleTag where id=:id";
|
Session session = this.getSessionFactory().openSession();
|
try {
|
Query query = session.createQuery(hql);
|
query.setString("settleTag", Constant.YN_Y);
|
query.setString("id", id);
|
query.executeUpdate();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
|
}
|