session应用二
从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应用二的更多相关文章
- 分布式中使用Redis实现Session共享(二)
上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见的session开始,刚好也重新学习一遍session的实现原理.在阅读之前假设你已经会使用nginx+i ...
- Session机制二(简易购物车案例)
一:案例一(简易购物车) 1.目录结构 2.step1.jsp <%@ page language="java" contentType="text/html; c ...
- [转]分布式中使用Redis实现Session共享(二)
本文转自:http://www.cnblogs.com/yanweidie/p/4678095.html 上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见 ...
- (转)分布式中使用Redis实现Session共享(二)
上一篇介绍了一些redis的安装及使用步骤,本篇开始将介绍redis的实际应用场景,先从最常见的session开始,刚好也重新学习一遍session的实现原理.在阅读之前假设你已经会使用nginx+i ...
- tomcat+nginx+redis实现均衡负载、session共享(二)
今天我们接着说上次还没完成session共享的部分,还没看过上一篇的朋友可以先看下上次内容,http://www.cnblogs.com/zhrxidian/p/5432886.html. 1.red ...
- 转:cookie和session(二)——php应用
文章来自于:http://blog.csdn.net/half1/article/details/21650211 本文将介绍cookie在session在php中的基本用法. 1.cookie ...
- Asp.Net HttpApplication请求管道与Session(二)
Asp.Net 回话的创建与结束 LogHelper.LogHelper _log = new LogHelper.LogHelper(); /// <summary> /// 程序开始- ...
- 本地存储 cookie,session,localstorage( 二)angular-local-storage
原文:https://github.com/grevory/angular-local-storage#api-documentation Get Started (1)Bower: $ bower ...
- tornado 自定义session (二)
有了上一步的基础,我们将session改造成一个模块,这样我们就可以通过配置,来使用不同方式(redis,数据库等)的session. 添加一个新目录:TornadoSession conf.py是配 ...
- Flask入门request session cookie(二)
1 HTTP方法分类 1 GET 浏览器告知服务器:只获取页面上的信息并发给我.这是最常用的方法. 2 HEAD 浏览器告诉服务器:欲获取信息,但是只关心消息头 .应用应像处理 GET 请求一样来处理 ...
随机推荐
- 在SSM框架中我设置拦截器filter不能通过注解获取到实现类
我在用注解注入实现类的时候,出现了这样的错误:如以下截图: 这个地方报出的错误是说明我的一个接口类型的类没有获取到,后来我就想要是我的实现类没有获取到那么我就直接new一个实现类然后再进行调用就会出现 ...
- PPAPI中使用Chromium的3D图形接口
使用PPAPI的Graphics 3D接口做了一个小演示样例,鼠标点击插件区域.绘制颜色,效果与ppapi_simple相似. foruok原创,如需转载请关注foruok的微信订阅号"程序 ...
- difference in physical path, root path, virutal path, relative virtual path, application path and aboslute path?
http://stackoverflow.com/questions/13869817/difference-in-physical-path-root-path-virutal-path-relat ...
- Linux系统的LOG日志文件及入侵后日志的清除
UNIX网管员主要是靠系统的LOG,来获得入侵的痕迹.当然也有第三方工具记录入侵系统的 痕迹,UNIX系统存放LOG文件,普通位置如下: /usr/adm - 早期版本的UNIX/var/adm - ...
- ADO.NET数据读取封装
public class sqlserver { //private string sqlstr = System.ConfigurationManager.ConnectionStrings[&qu ...
- P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- Android 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换
效果图如下 首先,要使用控件需要添加design library,在Android Studio中添加 compile 'com.android.support:design:23.4.0' 然后是布 ...
- Python(十) 函数式编程: 匿名函数、高阶函数、装饰器
一.lambda表达式 lambda parameter_list: expression # 匿名函数 def add(x,y): return x+y print(add(1,2)) f = la ...
- 紫书 例题 9-7 UVa 11584 (线性结构上的动态规划)
这道题判断回文串的方法非常的秀! 这里用到了记忆化搜索,因为会有很多重复 同时用kase来区分每一组数据 然后还有用递归来判断回文,很简洁 然后这种线性结构的动态规划的题,就是把 当前的这个数组分成两 ...
- jquery点击弹框外层关闭弹框
$(document).bind("click",function(e){ if($( e.target ).closest(".game-cont ...