From f52dcd3f333f87402903888b574d199d5987301f Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Tue, 4 Sep 2018 00:03:18 +0800 Subject: [PATCH] =?UTF-8?q?refac[litemall-db]:=20=E9=87=87=E7=94=A8?= =?UTF-8?q?=E4=B9=90=E8=A7=82=E9=94=81=E6=9B=B4=E6=96=B0=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/service/LitemallAdService.java | 4 ++-- .../db/service/LitemallAdminService.java | 4 ++-- .../db/service/LitemallBrandService.java | 4 ++-- .../db/service/LitemallCartService.java | 10 ++------ .../db/service/LitemallCategoryService.java | 4 ++-- .../db/service/LitemallCommentService.java | 23 +++---------------- .../LitemallGoodsAttributeService.java | 8 ------- .../db/service/LitemallGoodsService.java | 4 ++-- .../LitemallGoodsSpecificationService.java | 8 ------- .../service/LitemallGrouponRulesService.java | 4 ++-- .../db/service/LitemallGrouponService.java | 4 ++-- .../db/service/LitemallIssueService.java | 4 ++-- .../db/service/LitemallKeywordService.java | 10 ++------ .../db/service/LitemallOrderService.java | 18 +++------------ .../db/service/LitemallProductService.java | 4 ++-- .../db/service/LitemallStorageService.java | 11 ++------- .../service/LitemallSystemConfigService.java | 14 ----------- .../db/service/LitemallTopicService.java | 4 ++-- .../db/service/LitemallUserFormIdService.java | 2 +- .../db/service/LitemallUserService.java | 4 ++-- 20 files changed, 35 insertions(+), 113 deletions(-) diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java index 273ac69c..59468eb2 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdService.java @@ -56,8 +56,8 @@ public class LitemallAdService { return (int) adMapper.countByExample(example); } - public void updateById(LitemallAd ad) { - adMapper.updateByPrimaryKeySelective(ad); + public int updateById(LitemallAd ad) { + return adMapper.updateWithVersionByPrimaryKeySelective(ad.getVersion(), ad); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java index d5373b9d..66623c0b 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAdminService.java @@ -52,8 +52,8 @@ public class LitemallAdminService { return (int)adminMapper.countByExample(example); } - public void updateById(LitemallAdmin admin) { - adminMapper.updateByPrimaryKeySelective(admin); + public int updateById(LitemallAdmin admin) { + return adminMapper.updateWithVersionByPrimaryKeySelective(admin.getVersion(), admin); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java index 67eab9ff..78322940 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallBrandService.java @@ -76,8 +76,8 @@ public class LitemallBrandService { return (int) brandMapper.countByExample(example); } - public void updateById(LitemallBrand brand) { - brandMapper.updateByPrimaryKeySelective(brand); + public int updateById(LitemallBrand brand) { + return brandMapper.updateWithVersionByPrimaryKeySelective(brand.getVersion(), brand); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java index 1fa8f42c..80daee8a 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java @@ -25,8 +25,8 @@ public class LitemallCartService { cartMapper.insertSelective(cart); } - public void update(LitemallCart cart) { - cartMapper.updateByPrimaryKey(cart); + public int update(LitemallCart cart) { + return cartMapper.updateWithVersionByPrimaryKeySelective(cart.getVersion(), cart); } public List queryByUid(int userId) { @@ -42,12 +42,6 @@ public class LitemallCartService { return cartMapper.selectByExample(example); } - public List queryByUidAndSid(int userId, String sessionId) { - LitemallCartExample example = new LitemallCartExample(); - example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false); - return cartMapper.selectByExample(example); - } - public int delete(List productIdList, int userId) { LitemallCartExample example = new LitemallCartExample(); example.or().andUserIdEqualTo(userId).andProductIdIn(productIdList); diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java index 3f6f1c1e..2f7a26d7 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCategoryService.java @@ -86,8 +86,8 @@ public class LitemallCategoryService { return (int)categoryMapper.countByExample(example); } - public void updateById(LitemallCategory category) { - categoryMapper.updateByPrimaryKeySelective(category); + public int updateById(LitemallCategory category) { + return categoryMapper.updateWithVersionByPrimaryKeySelective(category.getVersion(), category); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java index 8f6ebfee..19b6c37b 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java @@ -40,7 +40,7 @@ public class LitemallCommentService { example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false); } else{ - Assert.state(false, "showType不支持"); + throw new RuntimeException("showType不支持"); } PageHelper.startPage(offset, limit); return commentMapper.selectByExample(example); @@ -55,21 +55,15 @@ public class LitemallCommentService { example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false); } else{ - Assert.state(false, ""); + throw new RuntimeException("showType不支持"); } return (int)commentMapper.countByExample(example); } - public Integer save(LitemallComment comment) { + public int save(LitemallComment comment) { return commentMapper.insertSelective(comment); } - - public void update(LitemallComment comment) { - commentMapper.updateByPrimaryKeySelective(comment); - } - - public List querySelective(String userId, String valueId, Integer page, Integer size, String sort, String order) { LitemallCommentExample example = new LitemallCommentExample(); example.setOrderByClause(LitemallComment.Column.addTime.desc()); @@ -106,19 +100,8 @@ public class LitemallCommentService { return (int)commentMapper.countByExample(example); } - public void updateById(LitemallComment comment) { - commentMapper.updateByPrimaryKeySelective(comment); - } - public void deleteById(Integer id) { commentMapper.logicalDeleteByPrimaryKey(id); } - public void add(LitemallComment comment) { - commentMapper.insertSelective(comment); - } - - public LitemallComment findById(Integer id) { - return commentMapper.selectByPrimaryKey(id); - } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java index 9f9ca4c3..0dd1c694 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsAttributeService.java @@ -20,14 +20,6 @@ public class LitemallGoodsAttributeService { return goodsAttributeMapper.selectByExample(example); } - public void updateById(LitemallGoodsAttribute goodsAttribute) { - goodsAttributeMapper.updateByPrimaryKeySelective(goodsAttribute); - } - - public void deleteById(Integer id) { - goodsAttributeMapper.logicalDeleteByPrimaryKey(id); - } - public void add(LitemallGoodsAttribute goodsAttribute) { goodsAttributeMapper.insertSelective(goodsAttribute); } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java index 1899cff3..c359deb3 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java @@ -222,8 +222,8 @@ public class LitemallGoodsService { return (int) goodsMapper.countByExample(example); } - public void updateById(LitemallGoods goods) { - goodsMapper.updateByPrimaryKeySelective(goods); + public int updateById(LitemallGoods goods) { + return goodsMapper.updateWithVersionByPrimaryKeySelective(goods.getVersion(), goods); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java index 82aba5d7..a459e1ce 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsSpecificationService.java @@ -27,14 +27,6 @@ public class LitemallGoodsSpecificationService { return goodsSpecificationMapper.selectByPrimaryKey(id); } - public void updateById(LitemallGoodsSpecification goodsSpecification) { - goodsSpecificationMapper.updateByPrimaryKeySelective(goodsSpecification); - } - - public void deleteById(Integer id) { - goodsSpecificationMapper.logicalDeleteByPrimaryKey(id); - } - public void deleteByGid(Integer gid) { LitemallGoodsSpecificationExample example = new LitemallGoodsSpecificationExample(); example.or().andGoodsIdEqualTo(gid); diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java index acd95b00..bc229ffa 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponRulesService.java @@ -109,7 +109,7 @@ public class LitemallGrouponRulesService { mapper.logicalDeleteByPrimaryKey(id); } - public void update(LitemallGrouponRules grouponRules) { - mapper.updateByPrimaryKeySelective(grouponRules); + public int update(LitemallGrouponRules grouponRules) { + return mapper.updateWithVersionByPrimaryKeySelective(grouponRules.getVersion(), grouponRules); } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java index bb26412a..6e16334e 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java @@ -90,8 +90,8 @@ public class LitemallGrouponService { return (int) mapper.countByExample(example); } - public void update(LitemallGroupon groupon) { - mapper.updateByPrimaryKey(groupon); + public int update(LitemallGroupon groupon) { + return mapper.updateWithVersionByPrimaryKeySelective(groupon.getVersion(), groupon); } /** diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java index bdb6ba16..72bebf03 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallIssueService.java @@ -58,8 +58,8 @@ public class LitemallIssueService { return (int)issueMapper.countByExample(example); } - public void updateById(LitemallIssue issue) { - issueMapper.updateByPrimaryKeySelective(issue); + public int updateById(LitemallIssue issue) { + return issueMapper.updateWithVersionByPrimaryKeySelective(issue.getVersion(), issue); } public LitemallIssue findById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java index e23ea387..444f8e71 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallKeywordService.java @@ -15,12 +15,6 @@ public class LitemallKeywordService { @Resource private LitemallKeywordMapper keywordsMapper; - public List queryDefaults() { - LitemallKeywordExample example = new LitemallKeywordExample(); - example.or().andIsDefaultEqualTo(true).andDeletedEqualTo(false); - return keywordsMapper.selectByExample(example); - } - public LitemallKeyword queryDefault() { LitemallKeywordExample example = new LitemallKeywordExample(); example.or().andIsDefaultEqualTo(true).andDeletedEqualTo(false); @@ -85,8 +79,8 @@ public class LitemallKeywordService { return keywordsMapper.selectByPrimaryKey(id); } - public void updateById(LitemallKeyword keywords) { - keywordsMapper.updateByPrimaryKeySelective(keywords); + public int updateById(LitemallKeyword keywords) { + return keywordsMapper.updateWithVersionByPrimaryKeySelective(keywords.getVersion(), keywords); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java index 3051a499..aa414034 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java @@ -23,12 +23,6 @@ public class LitemallOrderService { return orderMapper.insertSelective(order); } - public List query(Integer userId) { - LitemallOrderExample example = new LitemallOrderExample(); - example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false); - return orderMapper.selectByExample(example); - } - public int count(Integer userId) { LitemallOrderExample example = new LitemallOrderExample(); example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false); @@ -42,7 +36,7 @@ public class LitemallOrderService { private String getRandomNum(Integer num) { String base = "0123456789"; Random random = new Random(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < num; i++) { int number = random.nextInt(base.length()); sb.append(base.charAt(number)); @@ -50,13 +44,7 @@ public class LitemallOrderService { return sb.toString(); } - public LitemallOrder queryByOrderSn(Integer userId, String orderSn){ - LitemallOrderExample example = new LitemallOrderExample(); - example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false); - return orderMapper.selectOneByExample(example); - } - - public int countByOrderSn(Integer userId, String orderSn){ + private int countByOrderSn(Integer userId, String orderSn){ LitemallOrderExample example = new LitemallOrderExample(); example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false); return (int)orderMapper.countByExample(example); @@ -97,7 +85,7 @@ public class LitemallOrderService { } public int update(LitemallOrder order) { - return orderMapper.updateByPrimaryKeySelective(order); + return orderMapper.updateWithVersionByPrimaryKeySelective(order.getVersion(), order); } public List querySelective(Integer userId, String orderSn, List orderStatusArray, Integer page, Integer size, String sort, String order) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallProductService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallProductService.java index fb1c9c4d..6fdad968 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallProductService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallProductService.java @@ -24,8 +24,8 @@ public class LitemallProductService { return productMapper.selectByPrimaryKey(id); } - public void updateById(LitemallProduct product) { - productMapper.updateByPrimaryKeySelective(product); + public int updateById(LitemallProduct product) { + return productMapper.updateWithVersionByPrimaryKeySelective(product.getVersion(), product); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java index ffe3e4ac..48bc824f 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallStorageService.java @@ -25,23 +25,16 @@ public class LitemallStorageService { storageMapper.insertSelective(storageInfo); } - public LitemallStorage findByName(String filename) { - LitemallStorageExample example = new LitemallStorageExample(); - example.or().andNameEqualTo(filename).andDeletedEqualTo(false); - return storageMapper.selectOneByExample(example); - } - public LitemallStorage findByKey(String key) { LitemallStorageExample example = new LitemallStorageExample(); example.or().andKeyEqualTo(key).andDeletedEqualTo(false); return storageMapper.selectOneByExample(example); } - public void update(LitemallStorage storageInfo) { - storageMapper.updateByPrimaryKeySelective(storageInfo); + public int update(LitemallStorage storageInfo) { + return storageMapper.updateWithVersionByPrimaryKeySelective(storageInfo.getVersion(), storageInfo); } - public LitemallStorage findById(Integer id) { return storageMapper.selectByPrimaryKey(id); } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSystemConfigService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSystemConfigService.java index a1011f15..b47224f7 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSystemConfigService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallSystemConfigService.java @@ -13,23 +13,9 @@ public class LitemallSystemConfigService { @Resource private LitemallSystemMapper systemMapper; - public void add(LitemallSystem litemallSystem) { - systemMapper.insert(litemallSystem); - } - public List queryAll() { LitemallSystemExample example = new LitemallSystemExample(); example.or(); return systemMapper.selectByExample(example); } - - public LitemallSystem queryByKeyName(String keyName, String groupName) { - LitemallSystemExample example = new LitemallSystemExample(); - example.or().andKeyNameEqualTo(keyName); - return systemMapper.selectOneByExample(example); - } - - public void deleteById(Integer id) { - systemMapper.deleteByPrimaryKey(id); - } } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java index b5b03e58..99d4904e 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallTopicService.java @@ -91,10 +91,10 @@ public class LitemallTopicService { return (int) topicMapper.countByExample(example); } - public void updateById(LitemallTopic topic) { + public int updateById(LitemallTopic topic) { LitemallTopicExample example = new LitemallTopicExample(); example.or().andIdEqualTo(topic.getId()); - topicMapper.updateByExampleWithBLOBs(topic, example); + return topicMapper.updateWithVersionByExampleWithBLOBs(topic.getVersion(), topic, example); } public void deleteById(Integer id) { diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserFormIdService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserFormIdService.java index 6b4ae8b9..20504978 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserFormIdService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserFormIdService.java @@ -35,7 +35,7 @@ public class LitemallUserFormIdService { //更新或者删除缓存 if (userFormid.getIsprepay() && userFormid.getUseamount() > 1) { userFormid.setUseamount(userFormid.getUseamount() - 1); - formidMapper.updateByPrimaryKey(userFormid); + formidMapper.updateWithVersionByPrimaryKey(userFormid.getVersion(), userFormid); } else { formidMapper.deleteByPrimaryKey(userFormid.getId()); } diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java index 1bbc7e5d..67f06fc0 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java @@ -39,8 +39,8 @@ public class LitemallUserService { userMapper.insertSelective(user); } - public void update(LitemallUser user) { - userMapper.updateByPrimaryKeySelective(user); + public int update(LitemallUser user) { + return userMapper.updateWithVersionByPrimaryKeySelective(user.getVersion(), user); } public List querySelective(String username, String mobile, Integer page, Integer size, String sort, String order) {