package com.ld.igds.sh.service.impl; import com.bstek.bdf2.core.model.DefaultDept; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.ld.igds.inout.InoutConstant; import com.ld.igds.models.*; 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.List; import java.util.Map; /** * 上海接口---业务查询 * @author chen */ @Component public class HApiShServiceImpl extends HibernateDao { /** * 查询部门信息数据----接口1101和1102使用 * @param companyId * @param parentId * @return */ public List listDept(String companyId, String parentId) { String hql = " from " + DefaultDept.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isEmpty(parentId)){ hql += " and parentId is null"; }else { hql += " and parentId =:parentId"; args.put("parentId", parentId); } hql += " order by id desc"; return this.query(hql, args); } /** * 查询仓房信息数据----接口1103使用 * @param companyId * @param deptId * @return */ public List listBuilding(String companyId, String deptId) { String hql = " from " + Building.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(deptId)){ hql += " and deptId =:deptId"; args.put("deptId", deptId); } hql += " order by id desc"; return this.query(hql, args); } /** * 根据仓房id获取仓房信息 * @param companyId * @param id * @return */ public Building getBuilding(String companyId, String id) { if(StringUtils.isEmpty(id)){ return null; } String hql = " from " + Building.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); hql += " and id =:id"; args.put("id", id); hql += " order by id desc"; List buildings = this.query(hql, args); if(buildings == null || buildings.isEmpty()){ return null; } return buildings.get(0); } /** * 查询仓房信息数据----接口1104、1105、1106使用 * @param companyId * @param deptId * @return */ public List listDepot(String companyId, String deptId) { String hql = " from " + Depot.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(deptId)){ hql += " and deptId =:deptId"; args.put("deptId", deptId); } hql += " order by id desc"; return this.query(hql, args); } /** * 查询文件信息数据----接口1112使用 * @param companyId * @param startTime * @param endTime * @return */ public List listFiles(String companyId, Date startTime, Date endTime) { String hql = " from " + FileInfo.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(null != startTime){ hql += " and createTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and createTime <:endTime"; args.put("endTime", endTime); } hql += " order by createTime desc"; return this.query(hql, args); } /** * 查询质检数据----接口1201使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listQuality(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + MQuality.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and time >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and time <:endTime"; args.put("endTime", endTime); } hql += " order by time desc"; return this.query(hql, args); } /** * 询质检明细数据----接口1202使用 * @param checkId * @return */ public List listQualityDetail(String checkId) { String hql = " from " + CheckItem.class.getName() + " where checkId =:checkId"; Map args = new HashMap(); args.put("checkId", checkId); return this.query(hql, args); } /** * 查询出库通知单数据----接口1301使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listNoticeOut(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + InoutNoticeOut.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and createTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and createTime <:endTime"; args.put("endTime", endTime); } hql += " order by createTime desc"; return this.query(hql, args); } /** * 获取出库通知单 * @param companyId * @param id * @return */ public InoutNoticeOut getNoticeOut(String companyId, String id) { if(StringUtils.isEmpty(id)){ return null; } String hql = " from " + InoutNoticeOut.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); hql += " and id =:id"; args.put("id", id); hql += " order by createTime desc"; List list = this.query(hql, args); if(list == null || list.isEmpty()){ return null; } return list.get(0); } /** * 获取入库通知单 * @param companyId * @param id * @return */ public InoutNoticeIn getNoticeIn(String companyId, String id) { if(StringUtils.isEmpty(id)){ return null; } String hql = " from " + InoutNoticeIn.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); hql += " and id =:id"; args.put("id", id); hql += " order by createTime desc"; List list = this.query(hql, args); if(list == null || list.isEmpty()){ return null; } return list.get(0); } /** * 查询出入库数据----接口1302、1306使用 * @param companyId * @param depotId * @param startTime * @param endTime * @param type * @return */ public List listInoutRecord(String companyId, String depotId, Date startTime, Date endTime, String type) { String hql = " from " + InoutRecord.class.getName() + " where companyId =:companyId" + " and progress =:progress and recordStatus <>:recordStatus1 and recordStatus <>:recordStatus2"; Map args = new HashMap(); args.put("companyId", companyId); args.put("progress", InoutConstant.PROGRESS_RECORD); args.put("recordStatus1", InoutConstant.RECORD_STATUS_DEL); args.put("recordStatus2", "ERROR"); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and registerTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and registerTime <:endTime"; args.put("endTime", endTime); } if(StringUtils.isNotEmpty(type)){ hql += " and type =:type"; args.put("type", type); } hql += " order by registerTime desc"; return this.query(hql, args); } /** * 查询出入库结算信息数据----接口1304、1308使用 * @param companyId * @param id * @return */ public InoutSettle getInoutSettle(String companyId, String id) { String hql = " from " + InoutSettle.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); 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.isEmpty()){ return null; } return list.get(0); } /** * 查询出入库数据----接口1303使用 * @param companyId * @param checkId * @return */ public List listInoutChecks(String companyId, String checkId) { String hql = " from " + CheckItem.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(checkId)){ hql += " and checkId =:checkId"; args.put("checkId", checkId); } hql += " order by checkId desc"; return this.query(hql, args); } /** * 查询出入库结算信息数据----接口1304、1308使用 * @param companyId * @param depotId * @param startTime * @param endTime * @param type * @return */ public List listInoutSettle(String companyId, String depotId, Date startTime, Date endTime, String type) { String hql = " from " + InoutSettle.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and payTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and payTime <:endTime"; args.put("endTime", endTime); } if(StringUtils.isNotEmpty(type)){ hql += " and type =:type"; args.put("type", type); } hql += " order by payTime desc"; return this.query(hql, args); } /** * 查询出入库信息数据----接口1304、1308使用 * @param companyId * @param id * @return */ public InoutRecord getInoutRecord(String companyId, String id) { String hql = " from " + InoutRecord.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(id)){ hql += " and id =:id"; args.put("id", id); } hql += " order by id desc"; List list = this.query(hql, args); if(list == null || list.isEmpty()){ return null; } return list.get(0); } /** * 查询倒仓信息数据----接口1309使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listStockChange(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + InoutStockChange.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and updateTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and updateTime <:endTime"; args.put("endTime", endTime); } hql += " order by updateTime desc"; return this.query(hql, args); } /** * 查询损溢单数据----接口1311使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listLossOver(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + InoutLossOver.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and submitTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and submitTime <:endTime"; args.put("endTime", endTime); } hql += " order by submitTime"; return this.query(hql, args); } /** * 查询粮食性质变更信息----接口1312使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listFoodVarietyChange(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + InoutVarietyChange.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and changeTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and changeTime <:endTime"; args.put("endTime", endTime); } hql += " order by changeTime"; return this.query(hql, args); } /** * 查询温湿度信息----接口1401使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listGrain(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + Grain.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and receiveDate >=:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and receiveDate <=:endTime"; args.put("endTime", endTime); } hql += " order by receiveDate"; return this.query(hql, args); } /** * 查询粮情配置信息----接口1402使用 * @param companyId * @param depotId * @return */ public List listDepotConf(String companyId, String depotId) { String hql = " from " + DepotConf.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } hql += " order by depotId"; return this.query(hql, args); } /** * 查询通风信息----接口1403使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listAreationData(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + MAreationData.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and startTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and startTime <:endTime"; args.put("endTime", endTime); } hql += " order by startTime"; return this.query(hql, args); } /** * 查询熏蒸信息----接口1404使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listDrugLog(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + DrugLog.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and updateTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and updateTime <:endTime"; args.put("endTime", endTime); } hql += " order by updateTime"; return this.query(hql, args); } /** * 查询虫害信息----接口1405使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listPest(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + Pest.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and receiveDate >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and receiveDate <:endTime"; args.put("endTime", endTime); } hql += " order by receiveDate"; return this.query(hql, args); } /** * 查询虫害信息----接口1408使用 * @param companyId * @param depotId * @param startTime * @param endTime * @return */ public List listGas(String companyId, String depotId, Date startTime, Date endTime) { String hql = " from " + Gas.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(depotId)){ hql += " and depotId =:depotId"; args.put("depotId", depotId); } if(null != startTime){ hql += " and receiveDate >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and receiveDate <:endTime"; args.put("endTime", endTime); } hql += " order by receiveDate"; return this.query(hql, args); } /** * 查询轮换计划信息----接口1501使用 * @param companyId * @param type * @param startTime * @param endTime * @return */ public List listPlan(String companyId, String type, Date startTime, Date endTime) { String hql = " from " + InoutPlan.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(StringUtils.isNotEmpty(type)){ hql += " and type =:type"; args.put("type", type); } if(null != startTime){ hql += " and beginTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and beginTime <:endTime"; args.put("endTime", endTime); } hql += " order by beginTime"; return this.query(hql, args); } /** * 查询轮换明细计划信息----接口1502使用 * @param planId * @return */ public List getPlanDetail(String planId) { String hql = " from " + InoutPlanDetail.class.getName() + " where planId =:planId"; Map args = new HashMap(); args.put("planId", planId); return this.query(hql, args); } /** * 查询合同信息----接口1503使用 * @param companyId * @param startTime * @param endTime * @return */ public List listContract(String companyId, Date startTime, Date endTime){ String hql = " from " + InoutContract.class.getName() + " where companyId =:companyId"; Map args = new HashMap(); args.put("companyId", companyId); if(null != startTime){ hql += " and beginTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and beginTime <:endTime"; args.put("endTime", endTime); } hql += " order by beginTime"; return this.query(hql, args); } /** * 查询稻谷出入库数据----新增接口使用,每天定时查询 * @param companyId * @param startTime * @param endTime * @param type * * @param foodVariety * @return */ public List listInoutRecordByDay(String companyId, Date startTime, Date endTime, String type, String foodVariety) { String hql = " from " + InoutRecord.class.getName() + " where companyId =:companyId" + " and progress =:progress and recordStatus <>:recordStatus1 and recordStatus <>:recordStatus2"; Map args = new HashMap(); args.put("companyId", companyId); args.put("progress", InoutConstant.PROGRESS_RECORD); args.put("recordStatus1", InoutConstant.RECORD_STATUS_DEL); args.put("recordStatus2", "ERROR"); if(null != startTime){ hql += " and registerTime >:startTime"; args.put("startTime", startTime); } if(null != endTime){ hql += " and registerTime <:endTime"; args.put("endTime", endTime); } if(StringUtils.isNotEmpty(type)){ hql += " and type =:type"; args.put("type", type); } //稻谷 if(StringUtils.isNotEmpty(foodVariety)){ hql += " and foodVariety like:foodVariety"; args.put("foodVariety", foodVariety + "%"); } hql += " order by completeTime"; return this.query(hql, args); } public String saveToLsCcsslD(ToLsCcsslD data) { Session session = this.getSessionFactory().openSession(); try { session.saveOrUpdate(data); } finally { session.flush(); session.close(); } return null; } public String saveToLsRkjlD(ToLsRkjlD data) { Session session = this.getSessionFactory().openSession(); try { session.saveOrUpdate(data); } finally { session.flush(); session.close(); } return null; } }