public void saveDocumentMapping(JSONObject jobj) throws ServiceException { try { Docmap docMap = new Docmap(); if (jobj.has("docid") && !StringUtil.isNullOrEmpty(jobj.getString("docid"))) { Docs doc = (Docs) hibernateTemplate.get(Docs.class, jobj.getString("docid")); docMap.setDocid(doc); if (jobj.has("companyid") && !StringUtil.isNullOrEmpty(jobj.getString("companyid"))) { Company company = (Company) hibernateTemplate.get(Company.class, jobj.getString("companyid")); doc.setCompany(company); } if (jobj.has("userid") && !StringUtil.isNullOrEmpty(jobj.getString("userid"))) { User user = (User) hibernateTemplate.get(User.class, jobj.getString("userid")); doc.setUserid(user); } } if (jobj.has("refid")) { docMap.setRecid(jobj.getString("refid")); } if (jobj.has("map")) { docMap.setRelatedto(jobj.getString("map")); } hibernateTemplate.save(docMap); } catch (Exception ex) { throw ServiceException.FAILURE("documentDAOImpl.saveDocumentMapping", ex); } }
@SuppressWarnings("unchecked") public List<Team> getTeam(int userId, TeamType type) { boolean isAdmin = false; HibernateTemplate template = getHibernateTemplate(); Object obj = template.get(Employee.class, userId); List<Team> list = new ArrayList<Team>(); if (null == obj) return list; else { Employee employee = (Employee) obj; isAdmin = employee.getIsAdmin(); if (isAdmin) { DetachedCriteria criteria = DetachedCriteria.forClass(Team.class); if (type == TeamType.Product) criteria.add(Restrictions.eq("isProduct", true)); else if (type == TeamType.Sales) criteria.add(Restrictions.eq("isSales", true)); else if (type == TeamType.Operator) criteria.add(Restrictions.eq("isOperator", true)); criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); list = getHibernateTemplate().findByCriteria(criteria); } else { Set<Team> team = employee.getTeamMemberships(); for (Team team2 : team) { if (type == TeamType.Operator && team2.getIsOperator()) list.add(team2); else if (type == TeamType.Sales && team2.getIsSales()) list.add(team2); else if (type == TeamType.Product && team2.getIsProduct()) list.add(team2); } } return list; } }
@Override public E find(PK id) throws InstanceNotFoundException { E entity = ht.get(getEntityClass(), id); if (entity == null) { throw new InstanceNotFoundException(id, getEntityClass().getName()); } return entity; }
public boolean delUser(String userId) { User user = hibernateTemplate.get(User.class, userId); try { hibernateTemplate.delete(user); } catch (Exception e) { result = false; } return result; }
/* * (non-Javadoc) * * @see com.shengpay.qieke.qkcp.member.MemberRpt#getById(java.lang.Long) */ @Override @SuppressWarnings("unchecked") public Domain getById(Long id) { if (id == null) { return null; } return (Domain) hibernateTemplate.get(getDomainClass(), id); }
@Override public CcAndInferredLocationRecord getLastKnownRecordForVehicle(Integer vehicleId) throws Exception { if (vehicleId == null) { return null; } return _template.get(CcAndInferredLocationRecord.class, vehicleId); }
public Consumable findById(java.lang.Integer id) { log.debug("getting Consumable instance with id: " + id); try { Consumable instance = (Consumable) hibernateTemplate.get("cn.cas.iue.bean.Consumable", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public T get(PK id) { T entity = (T) hibernateTemplate.get(this.persistentClass, id); if (entity == null) { log.warn("Uh oh, '" + this.persistentClass + "' object with id '" + id + "' not found..."); throw new ObjectRetrievalFailureException(this.persistentClass, id); } return entity; }
public void testLoad() { Article article = (Article) hibernateTemplate.get(Article.class, Integer.valueOf(1)); assertNotNull(article); LOG.debug(article); assertEquals(2, article.getComments().size()); ArticleRepository repos = (ArticleRepository) context.getBean("articlesRepository"); assertEquals(1, repos.loadAll().size()); assertNotNull(repos.load("1")); }
public Object readAll(Object obj, HibernateTemplate ht) throws Exception { Object id = getEntityId(obj, ht); // System.out.println("entity id is " + id); Object main = ht.get(superClass, (java.io.Serializable) id); // todo entity no found // List r = ht.find("from BabyVisit where id = ?", id); // System.out.println("main is " + main); // System.out.println(r.size()); BeanUtils.copyProperties(main, obj); // spring beanutils loadDetails(obj, ht, fkName, id); return obj; }
@Override @Transactional(rollbackFor = Exception.class) public void receiveOperationPostCallback(ServletRequest request) throws TrusteeshipReturnException { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } String resp = request.getParameter("resp"); String sign = request.getParameter("sign"); log.debug(resp); log.debug(sign); boolean flag = CFCASignUtil.isVerifySign(resp, sign); log.debug(flag); if (flag) { // 处理账户开通成功 @SuppressWarnings("unchecked") Map<String, String> resultMap = Dom4jUtil.xmltoMap(resp); String code = resultMap.get("code"); String requestNo = resultMap .get("requestNo") .replaceFirst(YeePayConstants.RequestNoPre.UNBINDING_YEEPAY_BANKCARD, ""); String description = resultMap.get("description"); TrusteeshipOperation to = trusteeshipOperationBO.get( YeePayConstants.OperationType.UNBINDING_YEEPAY_BANKCARD, requestNo, requestNo, "yeepay"); if ("1".equals(code)) { BankCard bc = ht.get(BankCard.class, requestNo); if (bc != null) { bc.setStatus(BankCardConstants.BankCardStatus.DELETED); ht.update(bc); } to.setStatus(TrusteeshipConstants.Status.PASSED); to.setResponseTime(new Date()); to.setResponseData(resp); ht.update(to); } else { to.setStatus(TrusteeshipConstants.Status.REFUSED); to.setResponseTime(new Date()); to.setResponseData(description); ht.update(to); // 真实错误原因 throw new TrusteeshipReturnException(code + ":" + description); } } }
@Override @Transactional(readOnly = true) public Company find(long id) throws DaoException { Company company; try { company = hibernateTemplate.get(Company.class, id); } catch (DataAccessException e) { throw new DaoException("Error while calling find(long)"); } return company; }
public KwlReturnObject addTag(HashMap<String, Object> requestParams) throws ServiceException { String tag = requestParams.containsKey("tag") ? requestParams.get("tag").toString() : ""; List ll = new ArrayList(); int dl = 0; try { String tags[] = tag.split(",,"); Docs c = (Docs) hibernateTemplate.get(Docs.class, tags[0]); c.setTags(tags[1]); ll.add(c); } catch (Exception ex) { throw ServiceException.FAILURE("documentDAOImpl.addTag", ex); } return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl); }
public KwlReturnObject uploadFile(FileItem fi, String userid) throws ServiceException { Docs docObj = new Docs(); List ll = new ArrayList(); int dl = 0; try { String fileName = new String(fi.getName().getBytes(), "UTF8"); String Ext = ""; String a = ""; if (fileName.contains(".")) { Ext = fileName.substring(fileName.indexOf(".") + 1, fileName.length()); a = Ext.toUpperCase(); } User userObj = (User) hibernateTemplate.get(User.class, userid); docObj.setDocname(fileName); docObj.setUserid(userObj); docObj.setStorename(""); docObj.setDoctype(a + " " + "File"); docObj.setUploadedon(new Date()); docObj.setStorageindex(1); docObj.setDocsize(fi.getSize() + ""); hibernateTemplate.save(docObj); String fileid = docObj.getDocid(); if (Ext.length() > 0) { fileid = fileid + Ext; } docObj.setStorename(fileid); hibernateTemplate.update(docObj); ll.add(docObj); // String temp = "/home/trainee"; String temp = storageHandlerImplObj.GetDocStorePath(); uploadFile(fi, temp, fileid); } catch (Exception e) { throw ServiceException.FAILURE(e.getMessage(), e); } return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl); }
@Override @Transactional(rollbackFor = Exception.class) public void receiveOperationS2SCallback(ServletRequest request, ServletResponse response) { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } String notifyXML = request.getParameter("notify"); String sign = request.getParameter("sign"); @SuppressWarnings("unchecked") Map<String, String> resultMap = Dom4jUtil.xmltoMap(notifyXML); String cardNo = resultMap .get("requestNo") .replaceFirst(YeePayConstants.RequestNoPre.UNBINDING_YEEPAY_BANKCARD, ""); // String cardNo = resultMap.get("cardNo"); // String bank = resultMap.get("bank"); // String cardStatus = resultMap.get("cardStatus"); // String platformUserNo = resultMap.get("platformUserNo"); boolean flag = CFCASignUtil.isVerifySign(notifyXML, sign); log.debug(notifyXML); if (flag) { BankCard bc = ht.get(BankCard.class, cardNo); if (bc != null) { bc.setStatus(BankCardConstants.BankCardStatus.DELETED); ht.update(bc); } try { response.getWriter().print("SUCCESS"); FacesUtil.getCurrentInstance().responseComplete(); } catch (IOException e) { log.debug("trusteeshipBindingBancCard S2S response" + e.getMessage()); throw new RuntimeException(e.getMessage()); } } }
public Object saveOrUpdateAll(Object obj, HibernateTemplate ht, Session session) throws Exception { // System.out.println("saveOrUpdateAll"); Object id = getEntityId(obj, ht); if (id != null && !id.toString().trim().equals("")) { // System.out.println("saving"); Object old = ht.get(superClass, (Serializable) id); ht.evict(old); setInputInfo(old, obj); return updateAll(obj, ht, session); } else { setInputInfo(obj); Object main = superClass.newInstance(); BeanUtils.copyProperties(obj, main); // System.out.println("fkName is " + fkName); ht.save(main); id = getEntityId(main, ht); setFK(obj, id, fkName); saveDetails(obj, ht); return id; } }
@SuppressWarnings("unchecked") public Stat getStatById(int statId) { return hibernateTemplate.get(Stat.class, statId); }
@SuppressWarnings("unchecked") public StatCategory getStatCategoryById(int statCategoriesId) { return hibernateTemplate.get(StatCategory.class, statCategoriesId); }
@Override public <T> T getById(Class<T> cla, Long id) { return hibernateTemplate.get(cla, id); }
@Override public GroupHistory getGroupById(int id) { return ht.get(GroupHistory.class, id, LockMode.PESSIMISTIC_WRITE); }
@Transactional @Override public LookFor getLookForById(int lookForID) { return template.get(LookFor.class, lookForID); }
@Override public State getState(Long id) { return hibernateTemplate.get(State.class, id); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public boolean exists(PK id) { T entity = (T) hibernateTemplate.get(this.persistentClass, id); return entity != null; }
public Object load(Class type, String id) { return hibernateTemplate.get(type, new Integer(id)); }
public Faculty getFaculty(int facultyId) { return (Faculty) hibernateTemplate.get(Faculty.class, facultyId); }
public TestExecution selectTestExecutionById(Integer id) { return hibernateTemplate.get(TestExecution.class, id); }
public Manager findById(Integer userId) { return (Manager) hibernateTemplate.get(Manager.class, userId); }
@SuppressWarnings("unchecked") @Override @Transactional(rollbackFor = Exception.class) public void receiveOperationS2SCallback(ServletRequest request, ServletResponse response) { try { request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } String respXML = request.getParameter("notify"); // 响应的参数 为xml格式 log.debug("债权转让s2sCallback respXML:" + respXML.toString()); String sign = request.getParameter("sign"); // 签名 boolean flag = CFCASignUtil.isVerifySign(respXML, sign); if (flag) { // 验签成功 Map<String, String> map = Dom4jUtil.xmltoMap(respXML); String code = map.get("code"); String requestNo = map.get("requestNo").replaceFirst(YeePayConstants.RequestNoPre.TRANSFER, ""); if ("1".equals(code)) { // 易宝冻结金额成功 TrusteeshipOperation to = trusteeshipOperationBO.get(YeePayConstants.OperationType.TRANSFER, requestNo, "yeepay"); ht.evict(to); to = trusteeshipOperationBO.get(YeePayConstants.OperationType.TRANSFER, requestNo, "yeepay"); ht.evict(to); to = ht.get(TrusteeshipOperation.class, to.getId(), LockMode.UPGRADE); String[] params = to.getOperator().split("&"); Invest invest = ht.get(Invest.class, requestNo); // 债权购买人购买的债权转换成的一笔投资 TransferApply ta = ht.get(TransferApply.class, invest.getTransferApply().getId()); // 债权转让申请 if (TrusteeshipConstants.Status.PASSED.equals(to.getStatus())) { return; } // 调用易宝转账确认端口 boolean result = yeepayCpTransacionOperation.transactionComform( YeePayConstants.RequestNoPre.TRANSFER + requestNo, "CONFIRM"); if (result) { // 易宝转账确认成功 to.setStatus(TrusteeshipConstants.Status.PASSED); ht.update(to); /** * ***********************************平台操作begin************************************************** */ if (invest != null && ta != null) { invest.setStatus(InvestConstants.InvestStatus.REPAYING); invest.setTime(new Date()); // 成交时间 Invest orignInvest = ta.getInvest(); // 债权转让人转让的一笔投资 double investReaminCorpus = ArithUtil.sub(orignInvest.getMoney(), invest.getMoney()); // 原投资债权转让后剩余的投资金额 if (investReaminCorpus == 0.0) { orignInvest.setStatus(InvestStatus.COMPLETE); } orignInvest.setMoney(investReaminCorpus); double remainCorpus = transferService.calculateRemainCorpus(ta.getId()); // 未转出的本金 if (remainCorpus > 0.0) { // 债权未全部转出 ta.setStatus(TransferStatus.TRANSFERING); } else { // 债权全部转出 ta.setStatus(TransferStatus.TRANSFED); } // 债权的购买金额 double buyPrice = Double.parseDouble(params[0]); // 购买时候,扣除手续费,从转让人收到的金额中扣除。费用根据购买价格计算 double fee = feeConfigBO.getFee(FeePoint.TRANSFER, FeeType.FACTORAGE, null, null, buyPrice); // 购买时候,扣除手续费,从转让人收到的金额中扣除。费用根据购买价格计算 try { userBillBO.transferOutFromBalance( invest.getUser().getId(), buyPrice, OperatorInfo.TRANSFER_BUY, "债权:" + invest.getId() + "购买成功"); userBillBO.transferIntoBalance( ta.getInvest().getUser().getId(), buyPrice, OperatorInfo.TRANSFER, "债权:" + invest.getId() + "转让成功"); if (fee > 0.0) { sbs.transferInto(fee, OperatorInfo.TRANSFER, "购买债权手续费,编号:" + invest.getId()); userBillBO.transferOutFromBalance( ta.getInvest().getUser().getId(), fee, OperatorInfo.TRANSFER, "债权转让成功手续费,编号:" + ta.getId()); } } catch (InsufficientBalance e) { log.debug("s2sCallback债权转让平台划款时出错!"); // throw new RuntimeException("债权转让平台划款时出错!"); } ta.setInvest(orignInvest); ht.update(invest); ht.update(ta); double corpusRate = Double.parseDouble(params[1]); // 购买的本金占剩余本金的比例 generateTransferRepay( ta.getInvest().getInvestRepays(), invest, corpusRate); // 生成购买债权后的还款数据,调整之前的还款数据 /** * ***********************************平台操作end********************************************************* */ } } else { // 易宝转账确认失败 to.setStatus(TrusteeshipConstants.Status.REFUSED); ht.update(to); /** * ***********************************平台操作begin************************************************** * if(invest != null && ta != null){ * invest.setStatus(InvestConstants.InvestStatus.CANCEL); * ta.setStatus(TransferStatus.TRANSFERING); double buyPrice * =Double.parseDouble(params[0]) ;//债权的购买金额 try { * userBillBO.unfreezeMoney(invest.getUser().getId(),buyPrice,OperatorInfo.TRANSFER, "债权:" * + invest.getId()+ "购买失败"); } catch (InsufficientBalance e) { throw new * RuntimeException("购买债权:"+ invest.getId() + "失败,解冻金额时出错!"); } ht.update(invest); * ht.update(ta); } * ***********************************平台操作end************************************************** */ // throw new YeePayOperationException("债权转让易宝转账确认失败"); } } } else { // 验签失败 log.debug("债权转让验签失败"); } }
public User getUserById(String userId) { System.out.println("Dao ->userId:" + userId); return hibernateTemplate.get(User.class, userId); }
@Override @Transactional(rollbackFor = Exception.class) public TrusteeshipOperation createOperation(Invest invest, FacesContext fc) throws IOException { String transferApplyId = invest.getTransferApply().getId(); // 购买债权人的id String userId = invest.getUser().getId(); // 购买的债权本金 transferCorpus(投资时填写的投资额) double transferCorpus = invest.getInvestMoney(); double remainCorpus = transferService.calculateRemainCorpus(transferApplyId); if (transferCorpus <= 0 || transferCorpus > remainCorpus) { throw new YeePayOperationException("购买本金必须小于等于" + remainCorpus + "且大于0"); } TransferApply ta = ht.get(TransferApply.class, transferApplyId); // 购买的本金占剩余本金的比例corpusRate double corpusRate = ArithUtil.div(transferCorpus, remainCorpus); // 购买的本金占所有转让本金的比例corpusRateInAll double corpusRateInAll = ArithUtil.div(transferCorpus, ta.getCorpus()); // 投资人实际出的钱=债权的购买金额=债权转出价格*corpusRateInAll (债权转出价格=本金-折让金) double buyPrice = ArithUtil.mul(ta.getPrice(), corpusRateInAll, 2); if (buyPrice > userBillBO.getBalance(userId)) { throw new YeePayOperationException("余额不足。"); } // 购买时候,扣除手续费,从转让人收到的金额中扣除。费用根据购买价格计算 double fee = feeConfigBO.getFee(FeePoint.TRANSFER, FeeType.FACTORAGE, null, null, buyPrice); Invest investNew = new Invest(); investNew.setId(IdGenerator.randomUUID()); investNew.setMoney(transferCorpus); investNew.setStatus(InvestConstants.InvestStatus.CANCEL); investNew.setRate(ta.getInvest().getRate()); investNew.setTransferApply(ta); investNew.setLoan(ta.getInvest().getLoan()); investNew.setTime(new Date()); investNew.setUser(new User(userId)); investNew.setInvestMoney(transferCorpus); // 在这里添加投标状态是手动投标 investNew.setIsAutoInvest(false); ht.save(investNew); ht.update(ta); DecimalFormat currentNumberFormat = new DecimalFormat("#0.00"); // 构建投资参数实体 CPTransaction cp = new CPTransaction(); cp.setNotifyUrl( YeePayConstants.ResponseS2SUrl.PRE_RESPONSE_URL + YeePayConstants.OperationType.TRANSFER); cp.setCallbackUrl( YeePayConstants.ResponseWebUrl.PRE_RESPONSE_URL + YeePayConstants.OperationType.TRANSFER); // cp.setExpired(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(DateUtil.addMinute(new // Date(), 10))); cp.setRequestNo(YeePayConstants.RequestNoPre.TRANSFER + investNew.getId()); cp.setPlateformNo(YeePayConstants.Config.MER_CODE); cp.setPlatformUserNo(userId); cp.setBizType(YeepayCpTransactionConstant.CREDIT_ASSIGNMENT.name()); cp.setUserType("MEMBER"); // 资金明细 FundDetail fd = new FundDetail(); // 给转让债权的人的钱 fd.setAmount(currentNumberFormat.format(buyPrice - fee)); fd.setTargetPlatformUserNo(ta.getInvest().getUser().getId()); fd.setTargetUserType("MEMBER"); fd.setBizType(YeepayCpTransactionConstant.CREDIT_ASSIGNMENT.name()); cp.getFundDetails().add(fd); // 平台分润 if (fee > 0.0) { fd = new FundDetail(); // 投资人给平台的钱=fee fd.setAmount(currentNumberFormat.format(fee)); fd.setTargetPlatformUserNo(YeePayConstants.Config.MER_CODE); fd.setTargetUserType("MERCHANT"); fd.setBizType(YeepayCpTransactionConstant.COMMISSION.name()); cp.getFundDetails().add(fd); } // 扩展参数 Extend extend = new Extend(); Loan loan = ta.getInvest().getLoan(); extend.setTenderOrderNo(loan.getId()); extend.setCreditorPlatformUserNo(ta.getInvest().getUser().getId()); // 判断购买的债券是否是自动投标 if (ta.getInvest().getIsAutoInvest()) { extend.setOriginalRequestNo( YeePayConstants.RequestNoPre.AUTO_INVEST + ta.getInvest().getId()); } else { extend.setOriginalRequestNo(YeePayConstants.RequestNoPre.INVEST + ta.getInvest().getId()); } cp.setExtend(extend); log.debug(cp.toString()); Map<String, String> params = new HashMap<String, String>(); params.put("req", cp.toString()); String sign = CFCASignUtil.sign(cp.toString()); params.put("sign", sign); // 保存本地 TrusteeshipOperation to = new TrusteeshipOperation(); to.setId(IdGenerator.randomUUID()); to.setMarkId(investNew.getId()); to.setOperator(Double.toString(buyPrice) + "&" + Double.toString(corpusRate) + "&" + userId); to.setRequestUrl(YeePayConstants.RequestUrl.TRANSFER); to.setRequestData(MapUtil.mapToString(params)); to.setStatus(TrusteeshipConstants.Status.UN_SEND); to.setType(YeePayConstants.OperationType.TRANSFER); to.setTrusteeship("yeepay"); trusteeshipOperationBO.save(to); try { // 发送信息 sendOperation(to.getId(), "utf-8", fc); } catch (IOException e) { e.printStackTrace(); } return null; }