List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookService() { Session s = null;// w w w . jav a2 s . c om Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from ServiceInfo where state=0"); List<ServiceInfo> is = query.list(); for (ServiceInfo i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setOperateCardDate(v.getOperateCardTime()); s.saveOrUpdate(approval); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookServiceRight() { Session s = null;/*from w w w . ja va 2 s . c o m*/ Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from ServiceRightInfo where state=0"); List<ServiceRightInfo> is = query.list(); for (ServiceRightInfo i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setOperateCardDate(v.getOperateCardTime()); s.saveOrUpdate(approval); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleApprovalAction.java
public String vehicleApprovalInterrupt() { Session s = null;//from w ww . j av a 2 s . c o m Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Message msg = new Message(); msg.setFromUser(vehicleApproval.getInterruptPerson()); msg.setTime(new Date()); String reason = vehicleApproval.getInterruptReason(); User u = (User) s.get(User.class, vehicleApproval.getInterruptPerson()); vehicleApproval = (VehicleApproval) s.get(VehicleApproval.class, vehicleApproval.getId()); Contract c = (Contract) s.get(Contract.class, vehicleApproval.getContractId()); c.setState((short) -2); s.saveOrUpdate(c); vehicleApproval.setState(-vehicleApproval.getState()); vehicleApproval.setInterruptTime(new Date()); vehicleApproval.setInterruptPerson(u.getUid()); vehicleApproval.setInterruptReason(reason); s.saveOrUpdate(vehicleApproval); msg.setCarframeNum(c.getCarframeNum()); msg.setIdNum(c.getIdNum()); if (vehicleApproval.getCheckType() == 0) { msg.setType(""); if (StringUtils.isNotBlank(c.getCarNumOld()) && (c.getContractFrom() == null || c.getContractFrom() == 0)) { Query q_v = s.createQuery("from Vehicle where licenseNum = :carNum "); q_v.setString("carNum", c.getCarNumOld().trim()); q_v.setMaxResults(1); Vehicle v = (Vehicle) q_v.uniqueResult(); if (v != null) { v.setReused(false); s.saveOrUpdate(v); } } } else { msg.setType(""); } Driver d = (Driver) s.get(Driver.class, c.getIdNum()); msg.setMsg(String.format( "%tF %s?\n" + "%s(%s) %s(%s) %s ", msg.getTime(), u.getUname(), c.getCarNum(), c.getCarframeNum(), d.getName(), c.getIdNum(), reason)); s.saveOrUpdate(msg); Query q_us = s.createQuery(String.format( "from RelationUr where rid in (select rid from Role where rname in ('%s','%s','%s','%s','%s','%s','%s') ) ", "??", "????", "??", "?", "", "??", "")); List<RelationUr> users = q_us.list(); for (RelationUr relationUr : users) { MessageToUser mu = new MessageToUser(); mu.setUid(relationUr.getUid()); mu.setMid(msg.getId()); mu.setAlreadyRead(false); s.saveOrUpdate(mu); } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleApprovalService.java
/** * ?//from w w w . j a v a 2 s . com * @param _vehicleApproval * @return */ public boolean updateVehicleApproval(VehicleApproval _vehicleApproval) { HttpServletRequest request = null; int uName = 1; VehicleApproval vehicleApproval = vehicleApprovalDao.queryVehicleApprovalById(_vehicleApproval.getId()); int state = vehicleApproval.getState(); Contract contract = (Contract) ObjectAccess.getObject("com.dz.module.contract.Contract", vehicleApproval.getContractId()); // if(BooleanUtils.isTrue(contract.getGeneByImport())){ // request = new HttpServletRequest(){ // @Override // public AsyncContext getAsyncContext() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Object getAttribute(String name) { // // TODO Auto-generated method stub // return null; // } // // @Override // public Enumeration<String> getAttributeNames() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getCharacterEncoding() { // // TODO Auto-generated method stub // return null; // } // // @Override // public int getContentLength() { // // TODO Auto-generated method stub // return 0; // } // // @Override // public long getContentLengthLong() { // // TODO Auto-generated method stub // return 0; // } // // @Override // public String getContentType() { // // TODO Auto-generated method stub // return null; // } // // @Override // public DispatcherType getDispatcherType() { // // TODO Auto-generated method stub // return null; // } // // @Override // public ServletInputStream getInputStream() throws IOException { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getLocalAddr() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getLocalName() { // // TODO Auto-generated method stub // return null; // } // // @Override // public int getLocalPort() { // // TODO Auto-generated method stub // return 0; // } // // @Override // public Locale getLocale() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Enumeration<Locale> getLocales() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getParameter(String name) { // // TODO Auto-generated method stub // return null; // } // // @Override // public Map<String, String[]> getParameterMap() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Enumeration<String> getParameterNames() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String[] getParameterValues(String name) { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getProtocol() { // // TODO Auto-generated method stub // return null; // } // // @Override // public BufferedReader getReader() throws IOException { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRealPath(String path) { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRemoteAddr() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRemoteHost() { // // TODO Auto-generated method stub // return null; // } // // @Override // public int getRemotePort() { // // TODO Auto-generated method stub // return 0; // } // // @Override // public RequestDispatcher getRequestDispatcher(String path) { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getScheme() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getServerName() { // // TODO Auto-generated method stub // return null; // } // // @Override // public int getServerPort() { // // TODO Auto-generated method stub // return 0; // } // // @Override // public ServletContext getServletContext() { // // TODO Auto-generated method stub // return null; // } // // @Override // public boolean isAsyncStarted() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isAsyncSupported() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isSecure() { // // TODO Auto-generated method stub // return false; // } // // @Override // public void removeAttribute(String name) { // // TODO Auto-generated method stub // // } // // @Override // public void setAttribute(String name, Object o) { // // TODO Auto-generated method stub // // } // // @Override // public void setCharacterEncoding(String env) // throws UnsupportedEncodingException { // // TODO Auto-generated method stub // // } // // @Override // public AsyncContext startAsync() throws IllegalStateException { // // TODO Auto-generated method stub // return null; // } // // @Override // public AsyncContext startAsync(ServletRequest servletRequest, // ServletResponse servletResponse) // throws IllegalStateException { // // TODO Auto-generated method stub // return null; // } // // @Override // public boolean authenticate(HttpServletResponse response) // throws IOException, ServletException { // // TODO Auto-generated method stub // return false; // } // // @Override // public String changeSessionId() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getAuthType() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getContextPath() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Cookie[] getCookies() { // // TODO Auto-generated method stub // return null; // } // // @Override // public long getDateHeader(String name) { // // TODO Auto-generated method stub // return 0; // } // // @Override // public String getHeader(String name) { // // TODO Auto-generated method stub // return null; // } // // @Override // public Enumeration<String> getHeaderNames() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Enumeration<String> getHeaders(String name) { // // TODO Auto-generated method stub // return null; // } // // @Override // public int getIntHeader(String name) { // // TODO Auto-generated method stub // return 0; // } // // @Override // public String getMethod() { // // TODO Auto-generated method stub // return null; // } // // @Override // public Part getPart(String name) throws IOException, // ServletException { // // TODO Auto-generated method stub // return null; // } // // @Override // public Collection<Part> getParts() throws IOException, // ServletException { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getPathInfo() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getPathTranslated() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getQueryString() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRemoteUser() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRequestURI() { // // TODO Auto-generated method stub // return null; // } // // @Override // public StringBuffer getRequestURL() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getRequestedSessionId() { // // TODO Auto-generated method stub // return null; // } // // @Override // public String getServletPath() { // // TODO Auto-generated method stub // return null; // } // // @Override // public HttpSession getSession() { // // TODO Auto-generated method stub // return null; // } // // @Override // public HttpSession getSession(boolean create) { // // TODO Auto-generated method stub // return null; // } // // @Override // public Principal getUserPrincipal() { // // TODO Auto-generated method stub // return null; // } // // @Override // public boolean isRequestedSessionIdFromCookie() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isRequestedSessionIdFromURL() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isRequestedSessionIdFromUrl() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isRequestedSessionIdValid() { // // TODO Auto-generated method stub // return false; // } // // @Override // public boolean isUserInRole(String role) { // // TODO Auto-generated method stub // return false; // } // // @Override // public void login(String username, String password) // throws ServletException { // // TODO Auto-generated method stub // // } // // @Override // public void logout() throws ServletException { // // TODO Auto-generated method stub // // } // // @Override // public <T extends HttpUpgradeHandler> T upgrade( // Class<T> handlerClass) throws IOException, // ServletException { // // TODO Auto-generated method stub // return null; // } // // }; // }else{ // request = ServletActionContext.getRequest(); // uName = ((User)request.getSession().getAttribute("user")).getUid(); // } if (vehicleApproval.getCheckType() == 0) { if (state == 6)//? { vehicleApproval.setApprovalOfficeDate(new Date()); vehicleApproval.setState(8); vehicleApproval.setOfficeName(uName); vehicleApproval.setOfficeRemark(_vehicleApproval.getOfficeRemark()); vehicleApproval.setIsapprovalOffice(_vehicleApproval.getIsapprovalOffice()); // contractDao.changeState(_vehicleApproval.getContractId(),3); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = session.beginTransaction(); Contract cx = (Contract) session.get(Contract.class, _vehicleApproval.getContractId()); cx.setState((short) 3); session.update(cx); Message msg = new Message(); User u = (User) session.get(User.class, uName); msg.setFromUser(uName); msg.setTime(new Date()); msg.setCarframeNum(contract.getCarframeNum()); msg.setIdNum(contract.getIdNum()); msg.setType("?"); Driver d = (Driver) session.get(Driver.class, contract.getIdNum()); msg.setMsg(String.format("%tF %s?\n" + "%s(%s) %s(%s) ????", msg.getTime(), u.getUname(), contract.getCarNum(), contract.getCarframeNum(), d.getName(), contract.getIdNum())); session.save(msg); Query q_u = session.createQuery( "from RelationUr where " + "rid in (select rid from Role where rname = :rname )"); q_u.setString("rname", ""); List<RelationUr> users = q_u.list(); for (RelationUr relationUr : users) { MessageToUser mu = new MessageToUser(); mu.setUid(relationUr.getUid()); mu.setMid(msg.getId()); mu.setAlreadyRead(false); session.saveOrUpdate(mu); } session.update(vehicleApproval); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } return false; } finally { HibernateSessionFactory.closeSession(); } return true; } else if (state == 3)// { vehicleApproval.setApprovalFinanceDate(new Date()); vehicleApproval.setState(4); vehicleApproval.setFinanceName(uName); vehicleApproval.setFinanceRemark(_vehicleApproval.getFinanceRemark()); vehicleApproval.setIsapprovalFinance(_vehicleApproval.getIsapprovalFinance()); return vehicleApprovalDao.executeUpdate(vehicleApproval); } else if (state == 4)// { if (!BooleanUtils.isTrue(contract.getGeneByImport())) { String rentStr = (String) request.getParameter("contract.rent"); if (StringUtils.isNotBlank(rentStr)) { double rent = NumberUtils.toDouble(rentStr); contract.setRent(rent); ObjectAccess.saveOrUpdate(contract); } } vehicleApproval.setFinanceManagerApprovalDate(new Date()); vehicleApproval.setState(5); vehicleApproval.setFinanceManagerName(uName); vehicleApproval.setFinanceManagerRemark(_vehicleApproval.getFinanceManagerRemark()); vehicleApproval.setIsapprovalFinanceManager(_vehicleApproval.getIsapprovalFinanceManager()); return vehicleApprovalDao.executeUpdate(vehicleApproval); } // else if(state==4)//???-?? // { // vehicleApproval.setBranchManagerApprovalDate(new java.util.Date()); // vehicleApproval.setState(5); // vehicleApproval.setBranchManagerName(uName); // vehicleApproval.setBranchManagerRemark(_vehicleApproval.getBranchManagerRemark()); // vehicleApproval.setIsapprovalBranchManager(_vehicleApproval.getIsapprovalBranchManager()); // return vehicleApprovalDao.executeUpdate(vehicleApproval); // } else if (state == 1)//???-?? { String carframeNum = contract.getCarframeNum(); if (StringUtils.isEmpty(carframeNum)) { request.setAttribute("msgStr", "?--?"); return false; } Vehicle ve = ObjectAccess.getObject(Vehicle.class, carframeNum); if (ve != null && ve.getLicensePurseNum().matches("^\\w{6}")) { Vehicle ov = ObjectAccess.getObject(Vehicle.class, ve.getLicensePurseNum()); if (ov != null && ov.getState() < 2) { request.setAttribute("msgStr", "???"); return false; } } List<Insurance> ilist = ObjectAccess.query(Insurance.class, " carframeNum='" + contract.getCarframeNum() + "'"); boolean hasJQX = false, hasSX = false; for (Insurance insurance : ilist) { if (StringUtils.contains(insurance.getInsuranceClass(), "")) { if (new Date().before(insurance.getEndDate())) { hasJQX = true; } } else if (StringUtils.contains(insurance.getInsuranceClass(), "?")) { if (new Date().before(insurance.getEndDate())) { hasSX = true; } } } if (!hasJQX) { request.setAttribute("msgStr", ""); return false; } if (!hasSX) { request.setAttribute("msgStr", ""); return false; } vehicleApproval.setAssurerApprovalDate(new Date()); vehicleApproval.setState(2); vehicleApproval.setAssurerName(uName); vehicleApproval.setAssurerRemark(_vehicleApproval.getAssurerRemark()); vehicleApproval.setIsapprovalAssurer(_vehicleApproval.getIsapprovalAssurer()); vehicleApproval.setDamageInsurance(_vehicleApproval.getDamageInsurance()); vehicleApproval.setOnetimeAfterpay(_vehicleApproval.getOnetimeAfterpay()); vehicleApproval.setPayBeginDate(_vehicleApproval.getPayBeginDate()); vehicleApproval.setPayEndDate(_vehicleApproval.getPayEndDate()); return vehicleApprovalDao.executeUpdate(vehicleApproval); } else if (state == 2)//???-?? { // String carframeNum = contract.getCarframeNum(); // if(StringUtils.isEmpty(carframeNum)){ // request.setAttribute("msgStr", "?"); // return false; // } // // List<Insurance> ilist = ObjectAccess.query(Insurance.class, " carframeNum='"+contract.getCarframeNum()+"'"); // boolean hasJQX=false,hasSX = false; // for(Insurance insurance:ilist){ // if(StringUtils.equalsIgnoreCase(insurance.getInsuranceClass(),"")){ // if(new Date().before(insurance.getEndDate())){ // hasJQX = true; // } // }else if (StringUtils.equalsIgnoreCase(insurance.getInsuranceClass(), "??")) { // if(new Date().before(insurance.getEndDate())){ // hasSX = true; // } // } // } // // if(!hasJQX){ // request.setAttribute("msgStr", ""); // return false; // } // // if(!hasSX){ // request.setAttribute("msgStr", ""); // return false; // } // // if(vehicleApproval.getOperateCardDate()==null){ // request.setAttribute("msgStr", "???"); // return false; // } vehicleApproval.setManagerApprovalDate(new Date()); vehicleApproval.setState(3); vehicleApproval.setManagerName(uName); vehicleApproval.setManagerRemark(_vehicleApproval.getManagerRemark()); vehicleApproval.setIsapprovalManager(_vehicleApproval.getIsapprovalManager()); return vehicleApprovalDao.executeUpdate(vehicleApproval); } else if (state == 5)//?? { String carframeNum = contract.getCarframeNum(); if (StringUtils.isEmpty(carframeNum)) { request.setAttribute("msgStr", "?"); return false; } List<Insurance> ilist = ObjectAccess.query(Insurance.class, " carframeNum='" + contract.getCarframeNum() + "'"); boolean hasJQX = false, hasSX = false; for (Insurance insurance : ilist) { if (StringUtils.contains(insurance.getInsuranceClass(), "")) { if (new Date().before(insurance.getEndDate())) { hasJQX = true; } } else if (StringUtils.contains(insurance.getInsuranceClass(), "?")) { if (new Date().before(insurance.getEndDate())) { hasSX = true; } } } if (!hasJQX) { request.setAttribute("msgStr", ""); return false; } if (!hasSX) { request.setAttribute("msgStr", ""); return false; } // if(vehicleApproval.getOperateCardDate()==null){ // request.setAttribute("msgStr", "???"); // return false; // } vehicleApproval.setApprovalDirectorDate(new Date()); vehicleApproval.setState(6); vehicleApproval.setDirectorName(uName); vehicleApproval.setDirectorRemark(_vehicleApproval.getDirectorRemark()); vehicleApproval.setIsapprovalDirector(_vehicleApproval.getIsapprovalDirector()); vehicleApproval.setDiscountDays(_vehicleApproval.getDiscountDays()); contract.setDiscountDays(vehicleApproval.getDiscountDays()); ObjectAccess.saveOrUpdate(contract); // contractDao.changeState(_vehicleApproval.getContractId(),3); return vehicleApprovalDao.executeUpdate(vehicleApproval); } else return false; } else if (vehicleApproval.getCheckType() == 1) { if (state == 1) { //contract.setAbandonedTime(contract.getAbandonedTime() == null?new Date():contract.getAbandonedTime()); ObjectAccess.saveOrUpdate(contract); vehicleApproval.setAssurerRemark(_vehicleApproval.getAssurerRemark()); vehicleApproval.setAssurerName(uName); vehicleApproval.setAssurerApprovalDate(new Date()); vehicleApproval.setIsapprovalAssurer(_vehicleApproval.getIsapprovalAssurer()); vehicleApproval.setState(3);// } else if (state == 2) { vehicleApproval.setCashierRemark(_vehicleApproval.getCashierRemark()); vehicleApproval.setCashierName(uName); vehicleApproval.setCashierApprovalDate(new Date()); vehicleApproval.setState(3); } else if (state == 3) { String carframeNum = contract.getCarframeNum(); long count = ObjectAccess.execute(String .format("select count(*) from Accident where carId='%s' and status!=3 ", carframeNum)); if (count > 0) { request.setAttribute("msgStr", "?"); return false; } vehicleApproval.setManagerRemark(_vehicleApproval.getManagerRemark()); vehicleApproval.setManagerName(uName); vehicleApproval.setManagerApprovalDate(new Date()); vehicleApproval.setState(4); vehicleApproval.setIsapprovalManager(_vehicleApproval.getIsapprovalManager()); } else if (state == 4) { vehicleApproval.setOfficeRemark(_vehicleApproval.getOfficeRemark()); vehicleApproval.setOfficeName(uName); vehicleApproval.setApprovalOfficeDate(new Date()); vehicleApproval.setState(5); vehicleApproval.setIsapprovalOffice(_vehicleApproval.getIsapprovalOffice()); } else if (state == 5) { vehicleApproval.setFinanceRemark(_vehicleApproval.getFinanceRemark()); vehicleApproval.setFinanceName(uName); vehicleApproval.setApprovalFinanceDate(new Date()); vehicleApproval.setState(6); vehicleApproval.setIsapprovalFinance(_vehicleApproval.getIsapprovalFinance()); } else if (state == 6) { String rentStr = (String) request.getParameter("contract.rent"); if (StringUtils.isNotBlank(rentStr)) { double rent = NumberUtils.toDouble(rentStr); contract.setRent(rent); ObjectAccess.saveOrUpdate(contract); } vehicleApproval.setFinanceManagerRemark(_vehicleApproval.getFinanceManagerRemark()); vehicleApproval.setFinanceManagerName(uName); vehicleApproval.setFinanceManagerApprovalDate(new Date()); vehicleApproval.setState(7); vehicleApproval.setIsapprovalFinanceManager(_vehicleApproval.getIsapprovalFinanceManager()); } else if (state == 7) { vehicleApproval.setDirectorRemark(_vehicleApproval.getDirectorRemark()); vehicleApproval.setDirectorName(uName); vehicleApproval.setApprovalDirectorDate(new Date()); vehicleApproval.setState(8); vehicleApproval.setIsapprovalDirector(_vehicleApproval.getIsapprovalDirector()); Vehicle vehicle = ObjectAccess.getObject(Vehicle.class, contract.getCarframeNum()); String strT = (String) request.getParameter("contract.abandonedChargeTime"); if (StringUtils.isNotBlank(strT)) { SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd"); try { Date abandonedChargeTime = df.parse(strT); contract.setAbandonedChargeTime(abandonedChargeTime); } catch (ParseException e) { e.printStackTrace(); } } Session session = HibernateSessionFactory.getSession(); Transaction tx = null; try { tx = session.beginTransaction(); vehicle.setDriverId(null); if (vehicleApproval.getHandleMatter()) { vehicle.setState(3); } else { vehicle.setState(2); if (contract.getAbandonedTime() == null) { contract.setAbandonedTime(contract.getContractEndDate()); } //???? -305-25 Calendar sp = Calendar.getInstance(); sp.setTime(contract.getAbandonedTime()); Calendar endTime = Calendar.getInstance(); endTime.setTime(contract.getContractEndDate()); sp.add(Calendar.MONTH, 1); int amount = 0; while (sp.before(endTime)) { sp.add(Calendar.MONTH, 1); if (sp.after(endTime)) { if (endTime.get(Calendar.DATE) >= 20) { amount += 306 + 25; } break; } else { amount += 306 + 25; } } sp.setTime(contract.getAbandonedTime()); if (sp.get(Calendar.DATE) > 26) { sp.add(Calendar.MONTH, 1); } sp.set(Calendar.DATE, 1); ChargePlan tplan = new ChargePlan(); tplan.setContractId(contract.getId()); tplan.setFee(BigDecimal.valueOf(amount)); tplan.setFeeType("plan_sub_contract"); tplan.setInTime(new Date()); tplan.setComment("???306,25"); tplan.setTime(sp.getTime()); tplan.setIsClear(false); session.save(tplan); chargeDao.planTransfer(contract.getId(), DateUtil.getNextMonth(contract.getAbandonedTime()), contract.getId(), contract.getAbandonedTime()); List<String> dl = Arrays.<String>asList(vehicle.getFirstDriver(), vehicle.getSecondDriver(), vehicle.getThirdDriver(), vehicle.getTempDriver()); for (int i = 0; i < dl.size(); i++) { String idNum = dl.get(i); if (!StringUtils.isEmpty(idNum)) { Driver d = (Driver) session.get(Driver.class, idNum); if (d != null && d.getDriverClass() != null) { if (d.getDriverClass().equals("")) { vehicle.setFirstDriver(null); } else if (d.getDriverClass().equals("")) { vehicle.setSecondDriver(null); } else if (d.getDriverClass().equals("")) { vehicle.setThirdDriver(null); } else if (d.getDriverClass().equals("")) { vehicle.setTempDriver(null); } Driverincar record = new Driverincar(d.getCarframeNum(), d.getIdNum(), "", new Date()); record.setFinished(true); session.saveOrUpdate(record); //driverService.addDriverInCarRecord(record); d.setIsInCar(false); d.setRestTime(null); d.setCarframeNum(null); d.setDriverClass(null); d.setBusinessApplyTime(null); d.setBusinessApplyRegistrant(null); d.setBusinessApplyRegistTime(null); d.setBusinessReciveTime(null); d.setBusinessReciveRegistrant(null); d.setBusinessReciveRegistTime(null); d.setBusinessApplyCancelTime(null); d.setBusinessApplyCancelRegistrant(null); d.setBusinessApplyCancelRegistTime(null); d.setDept(null); d.setStatus(4); session.saveOrUpdate(d); } } } // contract.setAbandonedFinalTime(new Date()); } // switch(contract.getAbandonReason()){ // case "??": // vehicle.setState(2); // break; // case "": // case "": // vehicle.setState(3); // break; // } contract.setState((short) 1); session.saveOrUpdate(vehicle); session.saveOrUpdate(contract); session.saveOrUpdate(vehicleApproval); //contractDao.changeState(_vehicleApproval.getContractId(),1); Message msg = new Message(); User u = (User) session.get(User.class, uName); msg.setFromUser(uName); msg.setTime(new Date()); msg.setCarframeNum(contract.getCarframeNum()); msg.setIdNum(contract.getIdNum()); msg.setType("?"); Driver d = (Driver) session.get(Driver.class, contract.getIdNum()); msg.setMsg(String.format("%tF %s?\n" + "%s(%s) %s(%s) ??", msg.getTime(), u.getUname(), contract.getCarNum(), contract.getCarframeNum(), d.getName(), contract.getIdNum())); session.save(msg); Query q_u = session.createQuery( "from RelationUr where " + "rid in (select rid from Role where rname = :rname )" + "and uid in (select uid from User where position like :position)"); q_u.setString("rname", "??"); q_u.setString("position", "%" + contract.getBranchFirm().trim().charAt(0) + "%"); List<RelationUr> users = q_u.list(); for (RelationUr relationUr : users) { MessageToUser mu = new MessageToUser(); mu.setUid(relationUr.getUid()); mu.setMid(msg.getId()); mu.setAlreadyRead(false); session.saveOrUpdate(mu); } tx.commit(); return true; } catch (HibernateException ex) { ex.printStackTrace(); if (tx != null) tx.rollback(); } finally { session.flush(); HibernateSessionFactory.closeSession(); } return false; } return vehicleApprovalDao.executeUpdate(vehicleApproval); } else { return false; } }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w w w.j a v a 2 s . c o m public List<Vehicle> vehicleSearch(Page page, Vehicle vehicle, Triplet<String, String, Object>... conditions) throws HibernateException { // TODO Auto-generated method stub List<Vehicle> l = new ArrayList<Vehicle>(); Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Vehicle where state!=-1 "; if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { sql += "and engineNum like :engineNum "; } if (!StringUtils.isEmpty(vehicle.getCarMode())) { sql += "and carMode like :carMode "; } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { sql += "and certifyNum like :certifyNum "; } if (!StringUtils.isEmpty(vehicle.getDept())) { sql += "and dept like :dept "; } if (!StringUtils.isEmpty(vehicle.getDriverId())) { sql += "and driverId like :driverId "; } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { sql += "and licenseNum like :licenseNum "; } if (vehicle.getState() != null) { sql += "and state=:state "; } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } sql += " order by licenseNum "; Query query = session.createQuery(sql); query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { query.setString("engineNum", "%" + vehicle.getEngineNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getCarMode())) { query.setString("carMode", "%" + vehicle.getCarMode() + "%"); } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { query.setString("certifyNum", "%" + vehicle.getCertifyNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getDept())) { query.setString("dept", "%" + vehicle.getDept() + "%"); } if (!StringUtils.isEmpty(vehicle.getDriverId())) { query.setString("driverId", "%" + vehicle.getDriverId() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } if (vehicle.getState() != null) { query.setInteger("state", vehicle.getState()); } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } l = query.list(); query = null; } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@Override public int vehicleSearchCount(Vehicle vehicle, Triplet<String, String, Object>... conditions) throws HibernateException { // TODO Auto-generated method stub Session session = null;//from w ww . j a va2 s . c o m try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Vehicle where state!=-1 "; if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { sql += "and engineNum like :engineNum "; } if (!StringUtils.isEmpty(vehicle.getCarMode())) { sql += "and carMode like :carMode "; } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { sql += "and certifyNum like :certifyNum "; } if (!StringUtils.isEmpty(vehicle.getDept())) { sql += "and dept like :dept "; } if (!StringUtils.isEmpty(vehicle.getDriverId())) { sql += "and driverId like :driverId "; } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { sql += "and licenseNum like :licenseNum "; } if (vehicle.getState() != null) { sql += "and state=:state "; } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } Query query = session.createQuery(sql); if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getEngineNum())) { query.setString("engineNum", "%" + vehicle.getEngineNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getCarMode())) { query.setString("carMode", "%" + vehicle.getCarMode() + "%"); } if (!StringUtils.isEmpty(vehicle.getCertifyNum())) { query.setString("certifyNum", "%" + vehicle.getCertifyNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getDept())) { query.setString("dept", "%" + vehicle.getDept() + "%"); } if (!StringUtils.isEmpty(vehicle.getDriverId())) { query.setString("driverId", "%" + vehicle.getDriverId() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } if (vehicle.getState() != null) { query.setInteger("state", vehicle.getState()); } } for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.vehicle.VehicleDaoImpl.java
@Override public Vehicle selectByLicense(Vehicle vehicle) { Session session = null;/*from www . j a v a 2 s.c om*/ Transaction tx = null; Vehicle sql_vehicle = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); String sql = "from Vehicle where licenseNum = :license_num"; Query query = session.createQuery(sql); query.setString("license_num", vehicle.getLicenseNum()); sql_vehicle = (Vehicle) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return sql_vehicle; }
From source file:com.edgenius.core.dao.hibernate.CrFileNodeDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public CrFileNode getBaseByNodeUuid(final String nodeUuid) { Query query = getCurrentSesssion().createQuery(GET_BASE_BY_NODE_UUID); query.setString("uuid", nodeUuid); query.setMaxResults(1);/*from w w w .j av a 2s .c o m*/ List list = query.list(); if (list == null || list.size() == 0) return null; return (CrFileNode) list.get(0); }
From source file:com.edgenius.core.dao.hibernate.CrFileNodeDAOHibernate.java
License:Open Source License
public boolean removeByNodeUuid(final String nodeUuid) { Query query = getCurrentSesssion().createQuery(REMOVE_BY_NODE_UUID); query.setString("uuid", nodeUuid); query.executeUpdate();/*from www. j a va 2s .com*/ return true; }
From source file:com.edgenius.core.dao.hibernate.CrFileNodeDAOHibernate.java
License:Open Source License
public boolean removeVersion(final String nodeUuid, final Integer version) { Query query = getCurrentSesssion().createQuery(REMOVE_BY_NODE_UUID_VER); query.setString("uuid", nodeUuid); query.setInteger("version", version); int size = query.executeUpdate(); return size > 0 ? true : false; }