package com.ld.igds.phone35.service.impl; import com.bstek.bdf2.core.model.DefaultDept; import com.bstek.bdf2.core.model.DefaultUser; import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.ld.igds.constant.Constant; import com.ld.igds.inout.InoutConstant; import com.ld.igds.models.*; import com.ld.igds.phone35.param.Phone35InoutCommonParam; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 新版手机3.5,数据查询 * * @author chen */ @Component public class HPhoneServiceImpl extends HibernateDao { /** * 查询用户 * * @param username * @return */ public DefaultUser getUserByUsername(String username) { String hql = " from " + DefaultUser.class.getName() + " where username =:username"; Map args = new HashMap(); args.put("username", username); List list = this.query(hql, args); if (list == null || list.isEmpty()) { return null; } return list.get(0); } /** * 获取库区列表信息 * * @param companyId * @return */ public List listDept(String companyId) { String hql = " from " + DefaultDept.class.getName() + " where companyId =:companyId and val =:val"; Map args = new HashMap(); args.put("companyId", companyId); //库区启用 args.put("val", Constant.YN_Y); hql += " and parentId is not null"; hql += " order by id"; return this.query(hql, args); } /** * 获取仓库列表信息 * * @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"; return this.query(hql, args); } /** * 查询出入库信息,用于查询出入库记录、待值仓列表等 * * @param param * @return */ public List listInoutRecord(Phone35InoutCommonParam param) { String hql = " from " + InoutRecord.class.getName() + " where companyId =:companyId" + " and recordStatus <>:recordStatus1 "; Map args = new HashMap(); args.put("companyId", param.getCompanyId()); args.put("recordStatus1", InoutConstant.RECORD_STATUS_DEL); if (StringUtils.isNotEmpty(param.getDeptId())) { hql += " and deptId =:deptId"; args.put("deptId", param.getDeptId()); } if (StringUtils.isNotEmpty(param.getProgress())) { hql += " and progress =:progress"; args.put("progress", param.getProgress()); } if (StringUtils.isNotEmpty(param.getType())) { hql += " and type =:type"; args.put("type", param.getType()); } if (null != param.getStartTime()) { hql += " and completeTime >:startTime"; args.put("startTime", param.getStartTime()); } if (null != param.getEndTime()) { hql += " and completeTime <:endTime"; args.put("endTime", param.getEndTime()); } if (StringUtils.isNotEmpty(param.getPlateNum())) { hql += " and plateNum =:plateNum"; args.put("plateNum", "%" + param.getPlateNum() + "%"); } if (StringUtils.isNotEmpty(param.getIntelCard())) { hql += " and intelCard =:intelCard"; args.put("intelCard", param.getIntelCard()); } hql += " order by registerTime"; return this.query(hql, args); } /** * 根据组织编码、库区编码、流水id查询出入库信息 * 用于判断当前数据是否在值仓流程 * * @param companyId * @param deptId * @param id * @return */ public InoutRecord getInoutRecord(String companyId, String deptId, String id, String intelCard) { String hql = " from " + InoutRecord.class.getName() + " where" + " recordStatus <>:recordStatus1 "; Map args = new HashMap(); args.put("recordStatus1", InoutConstant.RECORD_STATUS_DEL); if (StringUtils.isNotEmpty(companyId)) { hql += " and companyId =:companyId"; args.put("companyId", companyId); } if (StringUtils.isNotEmpty(deptId)) { hql += " and deptId =:deptId"; args.put("deptId", deptId); } if (StringUtils.isNotEmpty(id)) { hql += " and id =:id"; args.put("id", id); } if (StringUtils.isNotEmpty(intelCard)) { hql += " and intelCard =:intelCard"; args.put("intelCard", intelCard); } hql += " order by registerTime desc"; List list = this.query(hql, args); if (null == list || list.isEmpty()) { return null; } return list.get(0); } /** * 查询仓房信息数据----接口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); } /** * 查询文件信息数据----接口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); } /** * 查询倒仓信息数据----接口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 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); } /** * 查询熏蒸信息----接口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 createTime >:startTime"; args.put("startTime", startTime); } if (null != endTime) { hql += " and createTime <:endTime"; args.put("endTime", endTime); } hql += " order by createTime"; 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 createTime >:startTime"; args.put("startTime", startTime); } if (null != endTime) { hql += " and createTime <:endTime"; args.put("endTime", endTime); } hql += " order by createTime"; return this.query(hql, args); } }