Commit b95e4ca7 authored by Junling Bu's avatar Junling Bu
Browse files

重大调整:除了订单更新采用乐观锁更新,其他表是普通更新

parent e4007338
...@@ -94,7 +94,7 @@ public class AdminAdController { ...@@ -94,7 +94,7 @@ public class AdminAdController {
return error; return error;
} }
if(adService.updateById(ad) == 0){ if(adService.updateById(ad) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(ad); return ResponseUtil.ok(ad);
......
...@@ -149,7 +149,7 @@ public class AdminAdminController { ...@@ -149,7 +149,7 @@ public class AdminAdminController {
admin.setPassword(encodedPassword); admin.setPassword(encodedPassword);
if(adminService.updateById(admin) == 0){ if(adminService.updateById(admin) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(admin); return ResponseUtil.ok(admin);
......
...@@ -102,7 +102,7 @@ public class AdminBrandController { ...@@ -102,7 +102,7 @@ public class AdminBrandController {
return error; return error;
} }
if(brandService.updateById(brand) == 0){ if(brandService.updateById(brand) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(brand); return ResponseUtil.ok(brand);
} }
......
...@@ -107,7 +107,7 @@ public class AdminCategoryController { ...@@ -107,7 +107,7 @@ public class AdminCategoryController {
} }
if(categoryService.updateById(category) == 0){ if(categoryService.updateById(category) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(); return ResponseUtil.ok();
} }
......
...@@ -136,7 +136,7 @@ public class AdminGrouponController { ...@@ -136,7 +136,7 @@ public class AdminGrouponController {
grouponRules.setPicUrl(goods.getPicUrl()); grouponRules.setPicUrl(goods.getPicUrl());
if(rulesService.updateById(grouponRules) == 0){ if(rulesService.updateById(grouponRules) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(); return ResponseUtil.ok();
......
...@@ -94,7 +94,7 @@ public class AdminIssueController { ...@@ -94,7 +94,7 @@ public class AdminIssueController {
return error; return error;
} }
if(issueService.updateById(issue) == 0){ if(issueService.updateById(issue) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(issue); return ResponseUtil.ok(issue);
......
...@@ -94,7 +94,7 @@ public class AdminKeywordController { ...@@ -94,7 +94,7 @@ public class AdminKeywordController {
return error; return error;
} }
if(keywordService.updateById(keywords) == 0){ if(keywordService.updateById(keywords) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(keywords); return ResponseUtil.ok(keywords);
} }
......
...@@ -127,6 +127,8 @@ public class AdminOrderController { ...@@ -127,6 +127,8 @@ public class AdminOrderController {
return ResponseUtil.fail(403, "订单不能确认收货"); return ResponseUtil.fail(403, "订单不能确认收货");
} }
Integer version = order.getVersion();
// 开启事务管理 // 开启事务管理
DefaultTransactionDefinition def = new DefaultTransactionDefinition(); DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
...@@ -134,7 +136,7 @@ public class AdminOrderController { ...@@ -134,7 +136,7 @@ public class AdminOrderController {
try { try {
// 设置订单取消状态 // 设置订单取消状态
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM); order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
if(orderService.updateById(order) == 0) { if(orderService.updateByIdWithVersion(version, order) == 0) {
throw new Exception("跟新数据已失效"); throw new Exception("跟新数据已失效");
} }
...@@ -199,6 +201,8 @@ public class AdminOrderController { ...@@ -199,6 +201,8 @@ public class AdminOrderController {
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
Integer version = order.getVersion();
// 如果订单不是已付款状态,则不能发货 // 如果订单不是已付款状态,则不能发货
if (!order.getOrderStatus().equals(OrderUtil.STATUS_PAY)) { if (!order.getOrderStatus().equals(OrderUtil.STATUS_PAY)) {
return ResponseUtil.fail(403, "订单不能确认收货"); return ResponseUtil.fail(403, "订单不能确认收货");
...@@ -208,7 +212,7 @@ public class AdminOrderController { ...@@ -208,7 +212,7 @@ public class AdminOrderController {
order.setShipSn(shipSn); order.setShipSn(shipSn);
order.setShipChannel(shipChannel); order.setShipChannel(shipChannel);
order.setShipTime(LocalDateTime.now()); order.setShipTime(LocalDateTime.now());
if(orderService.updateById(order) == 0){ if(orderService.updateByIdWithVersion(version, order) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDateExpired();
} }
...@@ -243,6 +247,8 @@ public class AdminOrderController { ...@@ -243,6 +247,8 @@ public class AdminOrderController {
continue; continue;
} }
Integer version = order.getVersion();
// 开启事务管理 // 开启事务管理
DefaultTransactionDefinition def = new DefaultTransactionDefinition(); DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
...@@ -251,7 +257,7 @@ public class AdminOrderController { ...@@ -251,7 +257,7 @@ public class AdminOrderController {
// 设置订单已取消状态 // 设置订单已取消状态
order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL); order.setOrderStatus(OrderUtil.STATUS_AUTO_CANCEL);
order.setEndTime(LocalDateTime.now()); order.setEndTime(LocalDateTime.now());
if(orderService.updateById(order) == 0){ if(orderService.updateByIdWithVersion(version, order) == 0){
throw new Exception("跟新数据已失效"); throw new Exception("跟新数据已失效");
} }
...@@ -264,12 +270,12 @@ public class AdminOrderController { ...@@ -264,12 +270,12 @@ public class AdminOrderController {
Integer number = product.getNumber() + orderGoods.getNumber(); Integer number = product.getNumber() + orderGoods.getNumber();
product.setNumber(number); product.setNumber(number);
if(productService.updateById(product) == 0){ if(productService.updateById(product) == 0){
throw new Exception("跟新数据已失效"); throw new Exception("跟新数据失败");
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
txManager.rollback(status); txManager.rollback(status);
logger.info("订单 ID=" + order.getId() + " 数据已经更新,放弃自动确认收货"); logger.info("订单 ID=" + order.getId() + " 数据更新失败,放弃自动确认收货");
return; return;
} }
txManager.commit(status); txManager.commit(status);
...@@ -306,10 +312,13 @@ public class AdminOrderController { ...@@ -306,10 +312,13 @@ public class AdminOrderController {
if (expired.isAfter(now)) { if (expired.isAfter(now)) {
continue; continue;
} }
Integer version = order.getVersion();
// 设置订单已取消状态 // 设置订单已取消状态
order.setOrderStatus(OrderUtil.STATUS_AUTO_CONFIRM); order.setOrderStatus(OrderUtil.STATUS_AUTO_CONFIRM);
order.setConfirmTime(now); order.setConfirmTime(now);
if(orderService.updateById(order) == 0){ if(orderService.updateByIdWithVersion(version, order) == 0){
logger.info("订单 ID=" + order.getId() + " 数据已经更新,放弃自动确认收货"); logger.info("订单 ID=" + order.getId() + " 数据已经更新,放弃自动确认收货");
} }
else{ else{
......
...@@ -75,7 +75,7 @@ public class AdminStorageController { ...@@ -75,7 +75,7 @@ public class AdminStorageController {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
if(litemallStorageService.update(litemallStorage) == 0){ if(litemallStorageService.update(litemallStorage) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(litemallStorage); return ResponseUtil.ok(litemallStorage);
} }
......
...@@ -99,7 +99,7 @@ public class AdminTopicController { ...@@ -99,7 +99,7 @@ public class AdminTopicController {
return error; return error;
} }
if(topicService.updateById(topic) == 0){ if(topicService.updateById(topic) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(topic); return ResponseUtil.ok(topic);
} }
......
...@@ -134,7 +134,7 @@ public class AdminUserController { ...@@ -134,7 +134,7 @@ public class AdminUserController {
user.setPassword(encodedPassword); user.setPassword(encodedPassword);
if(userService.updateById(user) == 0){ if(userService.updateById(user) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDataFailed();
} }
return ResponseUtil.ok(user); return ResponseUtil.ok(user);
} }
......
...@@ -57,7 +57,7 @@ public class LitemallAdService { ...@@ -57,7 +57,7 @@ public class LitemallAdService {
} }
public int updateById(LitemallAd ad) { public int updateById(LitemallAd ad) {
return adMapper.updateWithVersionByPrimaryKeySelective(ad.getVersion(), ad); return adMapper.updateByPrimaryKeySelective(ad);
} }
public void deleteById(Integer id) { public void deleteById(Integer id) {
......
...@@ -53,7 +53,7 @@ public class LitemallAdminService { ...@@ -53,7 +53,7 @@ public class LitemallAdminService {
} }
public int updateById(LitemallAdmin admin) { public int updateById(LitemallAdmin admin) {
return adminMapper.updateWithVersionByPrimaryKeySelective(admin.getVersion(), admin); return adminMapper.updateByPrimaryKeySelective(admin);
} }
public void deleteById(Integer id) { public void deleteById(Integer id) {
......
...@@ -77,7 +77,7 @@ public class LitemallBrandService { ...@@ -77,7 +77,7 @@ public class LitemallBrandService {
} }
public int updateById(LitemallBrand brand) { public int updateById(LitemallBrand brand) {
return brandMapper.updateWithVersionByPrimaryKeySelective(brand.getVersion(), brand); return brandMapper.updateByPrimaryKeySelective(brand);
} }
public void deleteById(Integer id) { public void deleteById(Integer id) {
......
...@@ -26,7 +26,7 @@ public class LitemallCartService { ...@@ -26,7 +26,7 @@ public class LitemallCartService {
} }
public int updateById(LitemallCart cart) { public int updateById(LitemallCart cart) {
return cartMapper.updateWithVersionByPrimaryKeySelective(cart.getVersion(), cart); return cartMapper.updateByPrimaryKeySelective(cart);
} }
public List<LitemallCart> queryByUid(int userId) { public List<LitemallCart> queryByUid(int userId) {
......
...@@ -87,7 +87,7 @@ public class LitemallCategoryService { ...@@ -87,7 +87,7 @@ public class LitemallCategoryService {
} }
public int updateById(LitemallCategory category) { public int updateById(LitemallCategory category) {
return categoryMapper.updateWithVersionByPrimaryKeySelective(category.getVersion(), category); return categoryMapper.updateByPrimaryKeySelective(category);
} }
public void deleteById(Integer id) { public void deleteById(Integer id) {
......
...@@ -223,7 +223,7 @@ public class LitemallGoodsService { ...@@ -223,7 +223,7 @@ public class LitemallGoodsService {
} }
public int updateById(LitemallGoods goods) { public int updateById(LitemallGoods goods) {
return goodsMapper.updateWithVersionByPrimaryKeySelective(goods.getVersion(), goods); return goodsMapper.updateByPrimaryKeySelective(goods);
} }
public void deleteById(Integer id) { public void deleteById(Integer id) {
......
...@@ -108,6 +108,6 @@ public class LitemallGrouponRulesService { ...@@ -108,6 +108,6 @@ public class LitemallGrouponRulesService {
} }
public int updateById(LitemallGrouponRules grouponRules) { public int updateById(LitemallGrouponRules grouponRules) {
return mapper.updateWithVersionByPrimaryKeySelective(grouponRules.getVersion(), grouponRules); return mapper.updateByPrimaryKeySelective(grouponRules);
} }
} }
...@@ -91,7 +91,7 @@ public class LitemallGrouponService { ...@@ -91,7 +91,7 @@ public class LitemallGrouponService {
} }
public int updateById(LitemallGroupon groupon) { public int updateById(LitemallGroupon groupon) {
return mapper.updateWithVersionByPrimaryKeySelective(groupon.getVersion(), groupon); return mapper.updateByPrimaryKeySelective(groupon);
} }
/** /**
......
...@@ -59,7 +59,7 @@ public class LitemallIssueService { ...@@ -59,7 +59,7 @@ public class LitemallIssueService {
} }
public int updateById(LitemallIssue issue) { public int updateById(LitemallIssue issue) {
return issueMapper.updateWithVersionByPrimaryKeySelective(issue.getVersion(), issue); return issueMapper.updateByPrimaryKeySelective(issue);
} }
public LitemallIssue findById(Integer id) { public LitemallIssue findById(Integer id) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment