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 page, InoutParam param) throws Exception { String hql = " from " + InoutRecord.class.getName() + " where companyId =:companyId and progress =:progress"; Map args = new HashMap(); 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 (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 args = new HashMap(); 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 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(); } } /** * 根据条件分页获取结算信息 * * @param page * @param param */ public void pageSettle(Page page, InoutParam param) throws Exception { String hql = " from " + InoutSettle.class.getName() + " where companyId =:companyId and deptId=:deptId"; Map args = new HashMap<>(); args.put("companyId", param.getCompanyId()); args.put("deptId", param.getDeptId()); if (StringUtils.isNotEmpty(param.getType())) { hql += " and inoutType =:inoutType"; args.put("inoutType", param.getType()); } if (StringUtils.isNotEmpty(param.getId())) { hql += " and id like:id"; args.put("id", "%" + param.getId() + "%"); } if (StringUtils.isNotEmpty(param.getDepotId())) { hql += " and depotId =:depotId"; args.put("depotId", param.getDepotId()); } if (null != param.getStart()) { hql += " and payTime >=:start"; args.put("start", DateUtil.getCurZero(param.getStart())); } if (null != param.getEnd()) { hql += " and payTime <=:end"; args.put("end", DateUtil.getNextZero(param.getEnd())); } String countHql = " select count(*) " + hql; hql += " order by id desc "; this.pagingQuery(page, hql, countHql, args); } }