从session中获取mapper对象,利用mapper对象进行增删改查

        Date now = new Date();
SqlSession session = this.yangchebaoDbManagerImpl.getSqlSessionFactory().openSession(false);
InsureQueryInfoMapper insureQueryInfoMapper = session.getMapper(InsureQueryInfoMapper.class);
InsureQuoteDetailMapper insureQuoteDetailMapper = session.getMapper(InsureQuoteDetailMapper.class); try {
boolean semSign = SemaphoreControllerUtil.getInstance().acquireInsureHandleSemaphore(sqId);
if(!semSign){
throw new BadRequestException("common", "请求被阻止,请稍后再试");
} InsureQueryInfo insureQueryInfo = this.queryInsureInfoBySqId(sqId, session);
// 只有保单报价查询信息不为空,而且报价状态允许进行报价处理时才处理,防止重复处理“报价成功”
if(insureQueryInfo!=null){
if(QunabaoNotifyStatus.canQuoteHandle(insureQueryInfo.getStatus())){
JSONObject dealBack = params.optJSONObject("dealBack");
//由于去哪保目前的是吧,只能靠此属性判断,所以临时处理
Boolean isSimilar = MapUtils.getBoolean(dealBack, "isSimilar", false);
if(isSimilar) {
notifyStatus = QunabaoNotifyStatus.QUOTE_FAILED;
}
if(notifyStatus.getCode()==QunabaoNotifyStatus.QUOTE_FAILED.getCode()){
// 报价失败
}else if(notifyStatus.getCode()==QunabaoNotifyStatus.QUOTE_SUCCESSED.getCode()){
// 报价成功
// 更新车船税价格、总价格、商业险价格、交强险价格
// 增加各险种的具体报价信息
JSONObject dealOffer = params.optJSONObject("dealOffer");
if(dealBack!=null && !dealBack.isEmpty()){
insureQueryInfo.setTaxCharge(dealBack.optDouble("taxCharge", PayConstants.DEFAULT_NULL_ID));// 车船税价格
insureQueryInfo.setTotalCharge(dealBack.optDouble("totalCharge", PayConstants.DEFAULT_NULL_ID));// 总价格
insureQueryInfo.setBizCharge(dealBack.optDouble("bizCharge", PayConstants.DEFAULT_NULL_ID));// 商业险价格
insureQueryInfo.setEfcCharge(dealBack.optDouble("efcCharge", PayConstants.DEFAULT_NULL_ID));// 交强险价格
} if(dealOffer!=null && !dealOffer.isEmpty()){
JSONObject suite = dealOffer.optJSONObject("suite");
if(suite!=null && !suite.isEmpty()){
JSONObject items = suite.optJSONObject("items");
if(items!=null && !items.isEmpty()){
Set entrySet = items.keySet();
Iterator<String> iterator = entrySet.iterator();
while(iterator.hasNext()){
String key = iterator.next();
JSONObject quoteInfo = items.optJSONObject(key);
if(quoteInfo!=null && !quoteInfo.isEmpty()){
InsureQuoteDetail insureQuoteDetail = new InsureQuoteDetail();
insureQuoteDetail.setSqid(sqId);// 单方号----例如““6010306151601232422”
insureQuoteDetail.setEcode(quoteInfo.optString("ecode"));// 保障项代码----例如:"VehicleDemageIns"
insureQuoteDetail.setSelIdx(quoteInfo.optString("selIdx"));// 选择项----例如:1
insureQuoteDetail.setSelName(quoteInfo.optString("caption"));// 选择项名称
insureQuoteDetail.setAmount(quoteInfo.optDouble("amount", PayConstants.DEFAULT_NULL_ID));// 保障金额
insureQuoteDetail.setCharge(quoteInfo.optDouble("charge", PayConstants.DEFAULT_NULL_ID));// 实际保费
insureQuoteDetail.setListPrice(quoteInfo.optDouble("listPrice", PayConstants.DEFAULT_NULL_ID));// 原价
insureQuoteDetail.setDiscountRate(quoteInfo.optDouble("discountRate", PayConstants.DEFAULT_NULL_ID));// 折扣率
insureQuoteDetail.setCreateDate(now);// 记录创建时间 insureQuoteDetailMapper.insert(insureQuoteDetail);// 增加险种报价信息
}
}
}
}
}
}
insureQueryInfo.setReceiveDate(now);// 报价回执时间 insureQueryInfo.setStatus(String.valueOf(notifyStatus.getCode()));// 报价状态----报价成功/失败
insureQueryInfo.setRemarks(notifyMsg);// 报价成功/失败描述信息 insureQueryInfoMapper.updateByPrimaryKey(insureQueryInfo);// 更新数据库记录 }else{
LOGGER.warn("去哪保回调----"+notifyStatus.getDesc()+"----单方号:"+sqId+"的状态为:"+insureQueryInfo.getStatus()+"忽略此回调");
}
}else{
throw new BadRequestException("common", "没有找到单方号"+sqId+"的信息");
} session.commit();
} catch(CarsmartException e) {
session.rollback();
throw new BadRequestException("common", e.getMessage());
} catch(Exception e) {
session.rollback();
LOGGER.error(e.getMessage(), e);
throw new InternalErrorException(e);
} finally {
session.close();
SemaphoreControllerUtil.getInstance().releaseInsureHandleSemaphore(sqId);
}

利用session  获取mapper对象进行更新的第二种方法利用 map存储变量,用session的update方法

    Map<String, Object> paramMap=new HashMap<String, Object>();
paramMap.put("modelQaId", modelQaId);
SqlSession session=null;
try {
session=this.yangchebaoDbManagerImpl.getSqlSessionFactory().openReplicableSqlSession(false);
session.update("cn.com.carsmart.ws.ibatis.mapper.ComplexQueryNewMapper.updateModelQaViewCnt", paramMap);
session.commit();
} catch(Exception e) {
if(null != session) {
session.rollback();
}
logger.error("method detail fail " + ExceptionUtils.getFullStackTrace(e));
} finally {
if(null != session) {
session.close();
}
}

session应用二的更多相关文章

  1. 分布式中使用Redis实现Session共享(二)

    上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见的session开始,刚好也重新学习一遍session的实现原理.在阅读之前假设你已经会使用nginx+i ...

  2. Session机制二(简易购物车案例)

    一:案例一(简易购物车) 1.目录结构 2.step1.jsp <%@ page language="java" contentType="text/html; c ...

  3. [转]分布式中使用Redis实现Session共享(二)

    本文转自:http://www.cnblogs.com/yanweidie/p/4678095.html 上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见 ...

  4. (转)分布式中使用Redis实现Session共享(二)

    上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见的session开始,刚好也重新学习一遍session的实现原理.在阅读之前假设你已经会使用nginx+i ...

  5. tomcat+nginx+redis实现均衡负载、session共享(二)

    今天我们接着说上次还没完成session共享的部分,还没看过上一篇的朋友可以先看下上次内容,http://www.cnblogs.com/zhrxidian/p/5432886.html. 1.red ...

  6. 转:cookie和session(二)——php应用

    文章来自于:http://blog.csdn.net/half1/article/details/21650211 本文将介绍cookie在session在php中的基本用法. 1.cookie   ...

  7. Asp.Net HttpApplication请求管道与Session(二)

    Asp.Net 回话的创建与结束 LogHelper.LogHelper _log = new LogHelper.LogHelper(); /// <summary> /// 程序开始- ...

  8. 本地存储 cookie,session,localstorage( 二)angular-local-storage

    原文:https://github.com/grevory/angular-local-storage#api-documentation Get Started (1)Bower: $ bower ...

  9. tornado 自定义session (二)

    有了上一步的基础,我们将session改造成一个模块,这样我们就可以通过配置,来使用不同方式(redis,数据库等)的session. 添加一个新目录:TornadoSession conf.py是配 ...

  10. Flask入门request session cookie(二)

    1 HTTP方法分类 1 GET 浏览器告知服务器:只获取页面上的信息并发给我.这是最常用的方法. 2 HEAD 浏览器告诉服务器:欲获取信息,但是只关心消息头 .应用应像处理 GET 请求一样来处理 ...

随机推荐

  1. ProFTPD 的 mod_lang模块

    ProFTPD 的 mod_lang模块http://www.proftpd.org/docs/modules/mod_lang.html安装该mod_lang模块随ProFTPD一起分发.要在pro ...

  2. 1.cocos_helloworld

    在class HelloWorld : public cocos2d::Layer中添加函数 void menuclose(cocos2d::Ref *psender); 实现: void Hello ...

  3. js图表插件绘制各种类型图表

    官网:http://www.bootcss.com/p/chart.js/ 中文参考手册:http://www.bootcss.com/p/chart.js/docs/ 一.生成折线图 :test.h ...

  4. 【转】一篇关于32位Linux内核使用大内存的文章——Hugemem Kernel Explained  &nb

    红旗DC系列Linux操作系统(x86平台)中带有四类核心: UP (支持单内核) SMP (支持多内核) hugemem Icc* (用intel C编译器编译的核心) 其中hugemem核心往往引 ...

  5. Swift学习笔记(8)--函数

    1.定义及调用 func sayHelloAgain(personName: String) -> String { return "Hello again, " + per ...

  6. CSUOJ 1635 Restaurant Ratings

    1635: Restaurant Ratings Time Limit: 1 Sec  Memory Limit: 128 MB Description A famous travel web sit ...

  7. Fastboot线刷“复活”之刷机心得(三)——错误处理

        在刷机的过程中可能不会是一帆风顺的.至少我是这种,总是会遇到这样或者那样的问题,下面是我为大家总结一些问题和解决办法,希望能对大家有所帮助. 一.电量问题     刷机和系统更新有一个共同的前 ...

  8. 转战Androidstudio之项目eclipse迁移

    新项目開始,决定转战as战场,(是应为听说了太多关于as的夸赞我才来的),期间各种不爽不适应历历在目啊.闲话少说,项目迁移開始 1.Eclipse迁出 当然直接从Eclipse迁出是有条件的,ADT必 ...

  9. 42.cnpm不是内部命令的解决方案:配置环境变量

    转自:https://blog.csdn.net/u014540814/article/details/78777961

  10. 带你底层看Sqoop如何转换成MapReduce作业运行的(代码程序)

    补充 其实啊,我们知道,sqoop在运行的时候,最终会去转换成mapreduce作业,这个很简单,不多赘述.直接贴出来. 具体这些怎么运行的,见我如下这篇博客.这里只做一个引子. Sqoop Impo ...