从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. JAVA并发-为现有的线程安全类添加原子方法

    JAVA中有许多线程安全的基础模块类,一般情况下,这些基础模块类能满足我们需要的所有操作,但更多时候,他们并不能满足我们所有的需要.此时,我们需要想办法在不破坏已有的线程安全类的基础上添加一个新的原子 ...

  2. git帮助命令

    git帮助命令 零.自己实例 cd D://software/code/PHP/phpStudy/PHPTutorial/WWW/github/m_Orchestrate git checkout - ...

  3. Centos7 网络出错(failed to start LSB: Bring up/down networking )

    这是我更换了VM虚拟机内存,重启后无法连接网络. 然后这是因为NetworkManager.service这个程序造成 解决方法: systemctl disable NetworkManager.s ...

  4. springboot 统一管理异常信息

    新建ResponseEntityExceptionHandler的继承类:(依然,需要入口类扫描) /** * @author sky * @version 1.0 */ @ControllerAdv ...

  5. Android 勤用RXJava compose操作符消除重复代码

    相信小伙伴在使用RXJava与Retrofit请求网络时,都有遇到过这样的场景,在IO线程请求网络解析数据,接着返回主线程setData.更新View试图,那么也肯定熟悉下面这几句代码: .subsc ...

  6. try/catch的用法

    1.try/catch用法基础介绍 try { //程序中抛出异常 throw value; } catch(valuetype v) { //例外处理程序段 } 语法小结:throw抛出值,catc ...

  7. VUE里子组件获取父组件动态变化的值

    在VUE里父组件给子组件间使用props方式传递数据,但是希望父组件的一个状态值改变然后子组件也能监听到这个数据的改变来更新子组件的状态. 场景:子组件通过props获取父组件传过来的数据,子组件存在 ...

  8. Vue_小练习

    <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <meta name ...

  9. Django_高级扩展

  10. Split Shape by Plane in OpenCASCADE

    Split Shape by Plane in OpenCASCADE eryar@163.com Abstract. Sometimes you want to split a shape by p ...