Selaa lähdekoodia

Merge remote-tracking branch 'origin/sit' into uat-20260202

dujian 14 tuntia sitten
vanhempi
commit
f1fd8ea471
23 muutettua tiedostoa jossa 1037 lisäystä ja 74 poistoa
  1. 34 0
      alien-entity/src/main/java/shop/alien/entity/store/dto/LifeFansFollowOutcome.java
  2. 14 14
      alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/OperationalActivityServiceImpl.java
  3. 11 10
      alien-store/src/main/java/shop/alien/store/controller/LifeUserController.java
  4. 184 49
      alien-store/src/main/java/shop/alien/store/service/LifeUserService.java
  5. 1 1
      alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java
  6. 51 0
      com/baomidou/mybatisplus/core/injector/methods/Delete.java
  7. 52 0
      com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java
  8. 50 0
      com/baomidou/mybatisplus/core/injector/methods/DeleteById.java
  9. 49 0
      com/baomidou/mybatisplus/core/injector/methods/DeleteByMap.java
  10. 69 0
      com/baomidou/mybatisplus/core/injector/methods/Insert.java
  11. 42 0
      com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java
  12. 42 0
      com/baomidou/mybatisplus/core/injector/methods/SelectById.java
  13. 42 0
      com/baomidou/mybatisplus/core/injector/methods/SelectByMap.java
  14. 39 0
      com/baomidou/mybatisplus/core/injector/methods/SelectCount.java
  15. 41 0
      com/baomidou/mybatisplus/core/injector/methods/SelectList.java
  16. 43 0
      com/baomidou/mybatisplus/core/injector/methods/SelectMaps.java
  17. 43 0
      com/baomidou/mybatisplus/core/injector/methods/SelectMapsPage.java
  18. 41 0
      com/baomidou/mybatisplus/core/injector/methods/SelectObjs.java
  19. 41 0
      com/baomidou/mybatisplus/core/injector/methods/SelectOne.java
  20. 41 0
      com/baomidou/mybatisplus/core/injector/methods/SelectPage.java
  21. 42 0
      com/baomidou/mybatisplus/core/injector/methods/Update.java
  22. 43 0
      com/baomidou/mybatisplus/core/injector/methods/UpdateById.java
  23. 22 0
      com/baomidou/mybatisplus/core/injector/methods/package-info.java

+ 34 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/LifeFansFollowOutcome.java

@@ -0,0 +1,34 @@
+package shop.alien.entity.store.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.io.Serializable;
+
+/**
+ * 关注/取消关注的业务执行结果(含明确提示文案)。
+ */
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+@ApiModel(description = "关注操作结果")
+public class LifeFansFollowOutcome implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "是否视为成功(含幂等已成功)")
+    private final boolean ok;
+
+    @ApiModelProperty(value = "展示给前端/用户的说明")
+    private final String message;
+
+    public static LifeFansFollowOutcome success(String message) {
+        return new LifeFansFollowOutcome(true, message);
+    }
+
+    public static LifeFansFollowOutcome failure(String message) {
+        return new LifeFansFollowOutcome(false, message);
+    }
+}

+ 14 - 14
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/OperationalActivityServiceImpl.java

@@ -179,22 +179,22 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
         }
         Integer result = 0;
         try {
-            String accessToken = getToken();
-            if (accessToken == null || accessToken.isEmpty()) {
-                log.error("获取AI服务 access_token 失败,无法创建活动");
-            } else {
-                AiContentModerationUtil.AuditResult auditResult = runActivityTextModeration(dto.getAuditParam());
-                applyModerationOutcomeToActivity(activity, auditResult);
-
-                result = activityMapper.insert(activity);
-                if (result > 0) {
-                    try {
-                        sendActivityAuditNotice(activity, auditResult.isPassed(), auditResult.getFailureReason());
-                    } catch (Exception e) {
-                        log.error("发送活动审核通知失败,activityId={}, error={}", activity.getId(), e.getMessage(), e);
-                    }
+//            String accessToken = getToken();
+//            if (accessToken == null || accessToken.isEmpty()) {
+//                log.error("获取AI服务 access_token 失败,无法创建活动");
+//            } else {
+            AiContentModerationUtil.AuditResult auditResult = runActivityTextModeration(dto.getAuditParam());
+            applyModerationOutcomeToActivity(activity, auditResult);
+
+            result = activityMapper.insert(activity);
+            if (result > 0) {
+                try {
+                    sendActivityAuditNotice(activity, auditResult.isPassed(), auditResult.getFailureReason());
+                } catch (Exception e) {
+                    log.error("发送活动审核通知失败,activityId={}, error={}", activity.getId(), e.getMessage(), e);
                 }
             }
+//            }
         } catch (Exception e) {
             log.error("创建活动/审核流程异常", e);
         }

+ 11 - 10
alien-store/src/main/java/shop/alien/store/controller/LifeUserController.java

@@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LifeFans;
 import shop.alien.entity.store.LifeUser;
+import shop.alien.entity.store.dto.LifeFansFollowOutcome;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.mapper.LifeUserMapper;
 import shop.alien.store.config.BaseRedisService;
@@ -97,24 +98,24 @@ public class LifeUserController {
     @ApiOperationSupport(order = 4)
     @PostMapping("/addFans")
     public R<Boolean> addFans(@RequestBody LifeFans fans) {
-        log.info("LifeUserController.addFans?fans={}", fans.toString());
-        int num = service.addFans(fans);
-        if (num == 0) {
-            return R.fail("关注失败");
+        log.info("LifeUserController.addFans fans={}", fans == null ? "null" : fans.toString());
+        LifeFansFollowOutcome outcome = service.addFans(fans);
+        if (!outcome.isOk()) {
+            return R.fail(outcome.getMessage());
         }
-        return R.success("关注成功");
+        return R.success(outcome.getMessage());
     }
 
     @ApiOperation("取消关注")
     @ApiOperationSupport(order = 5)
     @PostMapping("/cancelFollewed")
     public R<Boolean> cancelFollewed(@RequestBody LifeFans fans) {
-        log.info("LifeUserController.cancelFollewed?fans={}", fans.toString());
-        int num = service.cancelFans(fans);
-        if (num == 0) {
-            return R.fail("取消失败");
+        log.info("LifeUserController.cancelFollewed fans={}", fans == null ? "null" : fans.toString());
+        LifeFansFollowOutcome outcome = service.cancelFans(fans);
+        if (!outcome.isOk()) {
+            return R.fail(outcome.getMessage());
         }
-        return R.success("取消成功");
+        return R.success(outcome.getMessage());
     }
 
     @ApiOperation("搜索商家或用户")

+ 184 - 49
alien-store/src/main/java/shop/alien/store/service/LifeUserService.java

@@ -14,6 +14,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Triple;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -22,6 +25,7 @@ import shop.alien.config.properties.RiskControlProperties;
 import shop.alien.entity.second.LifeUserLog;
 import shop.alien.entity.second.SecondRiskControlRecord;
 import shop.alien.entity.store.*;
+import shop.alien.entity.store.dto.LifeFansFollowOutcome;
 import shop.alien.entity.store.vo.LifeMessageVo;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.entity.store.vo.WebSocketVo;
@@ -38,6 +42,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -54,6 +59,12 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
     private static final String FOLLOW_APP_PUSH_OPEN_PATH =
             "pages/secondHandTransactions/pages/message/noticesAndMessage";
 
+    /**
+     * 关注双方标识:`store_xxx` / `user_xxx`(整体无空格,后缀最长 120 字符)
+     */
+    private static final Pattern LIFE_FANS_PAIR_ID_PATTERN = Pattern.compile("^(store|user)_[^\\s]{1,120}$");
+    private static final int FAN_IDS_MAX_CHARS = 160;
+
     private final LifeUserMapper lifeUserMapper;
 
     private final LifeFansMapper lifeFansMapper;
@@ -84,6 +95,8 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
 
     private final StoreUserMapper storeUserMapper;
 
+    private final JdbcTemplate jdbcTemplate;
+
     @Autowired
     private RiskControlProperties riskControlProperties;
 
@@ -118,56 +131,164 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
         return lifeUserMapper.selectById(id);
     }
 
-    public int addFans(LifeFans fans) {
-        fans.setCreatedTime(new Date());
-        LambdaQueryWrapper<LifeFans> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-        lambdaQueryWrapper.eq(LifeFans::getFollowedId, fans.getFollowedId())
-                .eq(LifeFans::getFansId, fans.getFansId())
-                .eq(LifeFans::getDeleteFlag, 0);
-        int number = lifeFansMapper.selectCount(lambdaQueryWrapper);
-        if (number >= 1) {
-            return 0;
+    @Transactional(rollbackFor = Exception.class)
+    public LifeFansFollowOutcome addFans(LifeFans fans) {
+        Optional<String> paramError = validateAndNormalizeLifeFansPair(fans);
+        if (paramError.isPresent()) {
+            return LifeFansFollowOutcome.failure(paramError.get());
         }
-        int num = lifeFansMapper.insert(fans);
-
-        if (num == 1) {
-            LifeNotice notice = new LifeNotice();
-            notice.setTitle("关注通知");
-            notice.setContext("关注了你");
-            notice.setNoticeType(0);
-            notice.setReceiverId(fans.getFollowedId());
-            notice.setSenderId(fans.getFansId());
-
-            // 根据手机号查询发送人信息
-            String storePhones = "''";
-            String userPhones = "''";
-            if (fans.getFansId().split("_")[0].equals("store")) {
-                storePhones = "'" + fans.getFansId().split("_")[1] + "'";
-            } else {
-                userPhones = "'" + fans.getFansId().split("_")[1] + "'";
+
+        try {
+            fans.setCreatedTime(new Date());
+
+            LambdaQueryWrapper<LifeFans> activeQ = new LambdaQueryWrapper<>();
+            activeQ.eq(LifeFans::getFollowedId, fans.getFollowedId())
+                    .eq(LifeFans::getFansId, fans.getFansId())
+                    .last("LIMIT 1");
+            LifeFans active = lifeFansMapper.selectOne(activeQ);
+            if (active != null) {
+                return LifeFansFollowOutcome.success("您已关注,无需重复操作");
             }
-            List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
-            if (!CollectionUtils.isEmpty(userList)) {
-                notice.setBusinessId(userList.get(0).getId());
+
+            int revived = reviveDeletedFollowRow(fans.getFollowedId(), fans.getFansId());
+            if (revived > 0) {
+                sendFollowNoticeIfAllowed(fans);
+                return LifeFansFollowOutcome.success("关注成功");
             }
-            Integer followedLifeUserId = resolveLifeUserIdFromFollowedId(fans.getFollowedId());
-            boolean suppressNotice = followedLifeUserId != null
-                    && lifeUserPersonalizationSettingService.shouldSuppressFollowRelatedNotice(followedLifeUserId);
-            if (!suppressNotice) {
-                lifeNoticeMapper.insert(notice);
-
-                // 发送系统通知开关
-                if (uniPushOn) {
-                    try {
-                        sendFollowRelationAppPush(fans.getFollowedId());
-                    } catch (Exception e) {
-                        log.warn("关注 App 推送失败,followedId={},err={}", fans.getFollowedId(), e.getMessage());
-                    }
-                }
+
+            int num = lifeFansMapper.insert(fans);
+            if (num == 1) {
+                sendFollowNoticeIfAllowed(fans);
+                return LifeFansFollowOutcome.success("关注成功");
+            }
+            return LifeFansFollowOutcome.failure("关注失败:数据未保存成功,请稍后重试");
+        } catch (DuplicateKeyException ex) {
+            log.debug("addFans duplicate key (concurrent), followedId={} fansId={}", fans.getFollowedId(), fans.getFansId());
+            return LifeFansFollowOutcome.success("关注成功");
+        } catch (DataIntegrityViolationException ex) {
+            if (isDuplicateKeyMessage(ex)) {
+                return LifeFansFollowOutcome.success("关注成功");
             }
+            log.warn("addFans 数据约束异常 followedId={} fansId={} err={}",
+                    fans.getFollowedId(), fans.getFansId(), ex.getMessage());
+            return LifeFansFollowOutcome.failure("关注失败:数据校验未通过,请检查参数或稍后再试");
+        } catch (Exception ex) {
+            log.error("addFans 未预期异常 followedId={} fansId={}", fans.getFollowedId(), fans.getFansId(), ex);
+            return LifeFansFollowOutcome.failure("关注失败:系统繁忙,请稍后重试");
         }
+    }
 
-        return num;
+    private static boolean isDuplicateKeyMessage(DataIntegrityViolationException ex) {
+        Throwable t = ex.getMostSpecificCause();
+        String a = StringUtils.trimToEmpty(t != null ? t.getMessage() : "");
+        String b = StringUtils.trimToEmpty(ex.getMessage());
+        String m = (a + " | " + b).toLowerCase(Locale.ROOT);
+        return m.contains("duplicate") || m.contains("unique") || m.contains("uk_life_fans_follow_pair");
+    }
+
+    /**
+     * 校验并规范化一组关注标识;有错返回错误文案。
+     */
+    private Optional<String> validateAndNormalizeLifeFansPair(LifeFans fans) {
+        if (fans == null) {
+            return Optional.of("请求参数不能为空:请传入被关注方与粉丝标识");
+        }
+        String fid = StringUtils.trimToEmpty(fans.getFollowedId());
+        String sid = StringUtils.trimToEmpty(fans.getFansId());
+
+        fans.setFollowedId(normalizeFansPhoneId(fid));
+        fans.setFansId(normalizeFansPhoneId(sid));
+        fid = fans.getFollowedId();
+        sid = fans.getFansId();
+
+        if (StringUtils.isBlank(fid)) {
+            return Optional.of("被关注方标识(followedId)不能为空");
+        }
+        if (StringUtils.isBlank(sid)) {
+            return Optional.of("粉丝方标识(fansId)不能为空");
+        }
+        if (fid.length() > FAN_IDS_MAX_CHARS || sid.length() > FAN_IDS_MAX_CHARS) {
+            return Optional.of("关注标识过长(单字段不超过 " + FAN_IDS_MAX_CHARS + " 字符)");
+        }
+        Optional<String> fErr = assertValidFanPartyId("被关注方标识(followedId)", fid);
+        if (fErr.isPresent()) {
+            return fErr;
+        }
+        Optional<String> sErr = assertValidFanPartyId("粉丝方标识(fansId)", sid);
+        if (sErr.isPresent()) {
+            return sErr;
+        }
+        if (fid.equals(sid)) {
+            return Optional.of("无效操作:粉丝方与被关注方不能相同");
+        }
+        return Optional.empty();
+    }
+
+    private static String normalizeFansPhoneId(String raw) {
+        int u = raw.indexOf('_');
+        if (u <= 0) {
+            return raw;
+        }
+        String prefix = raw.substring(0, u).toLowerCase(Locale.ROOT);
+        return prefix + raw.substring(u);
+    }
+
+    private static Optional<String> assertValidFanPartyId(String label, String value) {
+        if (!LIFE_FANS_PAIR_ID_PATTERN.matcher(value).matches()) {
+            return Optional.of(label + "格式错误:须为 store_ 或 user_ 开头,且整体不能包含空格");
+        }
+        return Optional.empty();
+    }
+
+    /**
+     * 绕过 MyBatis-Plus 逻辑删除插件对 Mapper 手写 UPDATE 的条件注入风险,直接恢复一条软删的关注记录。
+     */
+    private int reviveDeletedFollowRow(String followedId, String fansId) {
+        return jdbcTemplate.update(
+                "UPDATE life_fans SET delete_flag = 0 WHERE followed_id = ? AND fans_id = ? AND delete_flag = 1 LIMIT 1",
+                followedId,
+                fansId);
+    }
+
+    private void sendFollowNoticeIfAllowed(LifeFans fans) {
+        LifeNotice notice = new LifeNotice();
+        notice.setTitle("关注通知");
+        notice.setContext("关注了你");
+        notice.setNoticeType(0);
+        notice.setReceiverId(fans.getFollowedId());
+        notice.setSenderId(fans.getFansId());
+
+        String storePhones = "''";
+        String userPhones = "''";
+        String sid = fans.getFansId();
+        String[] fp = sid.split("_", 2);
+        if (fp.length >= 2 && StringUtils.isNotBlank(fp[1])) {
+            if ("store".equalsIgnoreCase(fp[0])) {
+                storePhones = "'" + fp[1] + "'";
+            } else if ("user".equalsIgnoreCase(fp[0])) {
+                userPhones = "'" + fp[1] + "'";
+            }
+        } else {
+            log.warn("fansId 无法解析手机号段,跳过业务 id 回填,fansId={}", sid);
+        }
+        List<LifeMessageVo> userList = messageMapper.getLifeUserAndStoreUserByPhone(storePhones, userPhones);
+        if (!CollectionUtils.isEmpty(userList)) {
+            notice.setBusinessId(userList.get(0).getId());
+        }
+        Integer followedLifeUserId = resolveLifeUserIdFromFollowedId(fans.getFollowedId());
+        boolean suppressNotice = followedLifeUserId != null
+                && lifeUserPersonalizationSettingService.shouldSuppressFollowRelatedNotice(followedLifeUserId);
+        if (!suppressNotice) {
+            lifeNoticeMapper.insert(notice);
+
+            if (uniPushOn) {
+                try {
+                    sendFollowRelationAppPush(fans.getFollowedId());
+                } catch (Exception e) {
+                    log.warn("关注 App 推送失败,followedId={},err={}", fans.getFollowedId(), e.getMessage());
+                }
+            }
+        }
     }
 
     /**
@@ -238,11 +359,25 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
         return u != null ? u.getId() : null;
     }
 
-    public int cancelFans(LifeFans fans) {
-        LambdaUpdateWrapper<LifeFans> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(LifeFans::getFansId, fans.getFansId());
-        wrapper.eq(LifeFans::getFollowedId, fans.getFollowedId());
-        return lifeFansMapper.delete(wrapper);
+    @Transactional(rollbackFor = Exception.class)
+    public LifeFansFollowOutcome cancelFans(LifeFans fans) {
+        Optional<String> paramError = validateAndNormalizeLifeFansPair(fans);
+        if (paramError.isPresent()) {
+            return LifeFansFollowOutcome.failure(paramError.get());
+        }
+        try {
+            LambdaUpdateWrapper<LifeFans> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(LifeFans::getFansId, fans.getFansId());
+            wrapper.eq(LifeFans::getFollowedId, fans.getFollowedId());
+            int n = lifeFansMapper.delete(wrapper);
+            if (n <= 0) {
+                return LifeFansFollowOutcome.success("当前未关注或已取消,无需重复操作");
+            }
+            return LifeFansFollowOutcome.success("取消关注成功");
+        } catch (Exception ex) {
+            log.error("cancelFans 失败 followedId={} fansId={}", fans.getFollowedId(), fans.getFansId(), ex);
+            return LifeFansFollowOutcome.failure("取消关注失败:系统繁忙,请稍后重试");
+        }
     }
 
     public IPage<LifeUserVo> getStoreAndUserByName(LifeUserVo vo) {

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -6068,7 +6068,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                     fansWrapper.eq(LifeFans::getFollowedId, followedId)
                             .eq(LifeFans::getFansId, fansId)
                             .eq(LifeFans::getDeleteFlag, 0);
-                    LifeFans lifeFans = lifeFansMapper.selectOne(fansWrapper);
+                    LifeFans lifeFans = lifeFansMapper.selectOne(fansWrapper.last("LIMIT 1"));
 
                     if (lifeFans != null) {
                         result.setIsFollowed(1); // 已关注

+ 51 - 0
com/baomidou/mybatisplus/core/injector/methods/Delete.java

@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据 entity 条件删除记录
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class Delete extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        String sql;
+        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE;
+        if (tableInfo.isLogicDelete()) {
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
+                sqlWhereEntityWrapper(true, tableInfo),
+                sqlComment());
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+            return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+        } else {
+            sqlMethod = SqlMethod.DELETE;
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
+                sqlWhereEntityWrapper(true, tableInfo),
+                sqlComment());
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+            return this.addDeleteMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource);
+        }
+    }
+}

+ 52 - 0
com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java

@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据 ID 集合删除
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class DeleteBatchByIds extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        String sql;
+        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BATCH_BY_IDS;
+        if (tableInfo.isLogicDelete()) {
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
+                tableInfo.getKeyColumn(),
+                SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
+                tableInfo.getLogicDeleteSql(true, false));
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
+            return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+        } else {
+            sqlMethod = SqlMethod.DELETE_BATCH_BY_IDS;
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),
+                SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA));
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
+            return this.addDeleteMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource);
+        }
+    }
+}

+ 50 - 0
com/baomidou/mybatisplus/core/injector/methods/DeleteById.java

@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据 ID 删除
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class DeleteById extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        String sql;
+        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_ID;
+        if (tableInfo.isLogicDelete()) {
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
+                tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
+                tableInfo.getLogicDeleteSql(true, false));
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
+            return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+        } else {
+            sqlMethod = SqlMethod.DELETE_BY_ID;
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(),
+                tableInfo.getKeyProperty());
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
+            return this.addDeleteMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource);
+        }
+    }
+}

+ 49 - 0
com/baomidou/mybatisplus/core/injector/methods/DeleteByMap.java

@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import java.util.Map;
+
+/**
+ * 根据columnMap 条件删除记录
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class DeleteByMap extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        String sql;
+        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE_BY_MAP;
+        if (tableInfo.isLogicDelete()) {
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo), sqlWhereByMap(tableInfo));
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
+            return addUpdateMappedStatement(mapperClass, Map.class, sqlMethod.getMethod(), sqlSource);
+        } else {
+            sqlMethod = SqlMethod.DELETE_BY_MAP;
+            sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), this.sqlWhereByMap(tableInfo));
+            SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
+            return this.addDeleteMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource);
+        }
+    }
+}

+ 69 - 0
com/baomidou/mybatisplus/core/injector/methods/Insert.java

@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
+import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
+import org.apache.ibatis.executor.keygen.KeyGenerator;
+import org.apache.ibatis.executor.keygen.NoKeyGenerator;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 插入一条数据(选择字段插入)
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+@SuppressWarnings("all")
+public class Insert extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        KeyGenerator keyGenerator = new NoKeyGenerator();
+        SqlMethod sqlMethod = SqlMethod.INSERT_ONE;
+        String columnScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlColumnMaybeIf(),
+            LEFT_BRACKET, RIGHT_BRACKET, null, COMMA);
+        String valuesScript = SqlScriptUtils.convertTrim(tableInfo.getAllInsertSqlPropertyMaybeIf(null),
+            LEFT_BRACKET, RIGHT_BRACKET, null, COMMA);
+        String keyProperty = null;
+        String keyColumn = null;
+        // 表包含主键处理逻辑,如果不包含主键当普通字段处理
+        if (StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
+            if (tableInfo.getIdType() == IdType.AUTO) {
+                /** 自增主键 */
+                keyGenerator = new Jdbc3KeyGenerator();
+                keyProperty = tableInfo.getKeyProperty();
+                keyColumn = tableInfo.getKeyColumn();
+            } else {
+                if (null != tableInfo.getKeySequence()) {
+                    keyGenerator = TableInfoHelper.genKeyGenerator(tableInfo, builderAssistant, sqlMethod.getMethod(), languageDriver);
+                    keyProperty = tableInfo.getKeyProperty();
+                    keyColumn = tableInfo.getKeyColumn();
+                }
+            }
+        }
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), columnScript, valuesScript);
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addInsertMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource, keyGenerator, keyProperty, keyColumn);
+    }
+}

+ 42 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据ID集合,批量查询数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectBatchByIds extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BATCH_BY_IDS;
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
+            sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(),
+            SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
+            tableInfo.getLogicDeleteSql(true, false)), Object.class);
+        return addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 42 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectById.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+import org.apache.ibatis.scripting.defaults.RawSqlSource;
+
+/**
+ * 根据ID 查询一条数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectById extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.LOGIC_SELECT_BY_ID;
+        SqlSource sqlSource = new RawSqlSource(configuration, String.format(sqlMethod.getSql(),
+            sqlSelectColumns(tableInfo, false),
+            tableInfo.getTableName(), tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
+            tableInfo.getLogicDeleteSql(true, false)), Object.class);
+        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 42 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectByMap.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import java.util.Map;
+
+/**
+ * 根据columnMap 查询一条数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectByMap extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_BY_MAP;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false),
+            tableInfo.getTableName(), sqlWhereByMap(tableInfo));
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Map.class);
+        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 39 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectCount.java

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 查询满足条件总记录数
+ *
+ * @author hubin
+ * @since 2018-04-08
+ */
+public class SelectCount extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_COUNT;
+        String sql = String.format(sqlMethod.getSql(), this.sqlCount(), tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Integer.class);
+    }
+}

+ 41 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectList.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 查询满足条件所有数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectList extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_LIST;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 43 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectMaps.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import java.util.Map;
+
+/**
+ * 查询满足条件所有数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectMaps extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_MAPS;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class);
+    }
+}

+ 43 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectMapsPage.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+import java.util.Map;
+
+/**
+ * 查询满足条件所有数据(并翻页)
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectMapsPage extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_MAPS_PAGE;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class);
+    }
+}

+ 41 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectObjs.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 查询满足条件所有数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectObjs extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_OBJS;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectObjsColumns(tableInfo),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Object.class);
+    }
+}

+ 41 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectOne.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 查询满足条件一条数据
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectOne extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_ONE;
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
+            this.sqlSelectColumns(tableInfo, true), tableInfo.getTableName(),
+            this.sqlWhereEntityWrapper(true, tableInfo), sqlComment()),
+            modelClass);
+        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 41 - 0
com/baomidou/mybatisplus/core/injector/methods/SelectPage.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 查询满足条件所有数据(并翻页)
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class SelectPage extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.SELECT_PAGE;
+        String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, true),
+            tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
+    }
+}

+ 42 - 0
com/baomidou/mybatisplus/core/injector/methods/Update.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据 whereEntity 条件,更新记录
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class Update extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        SqlMethod sqlMethod = SqlMethod.UPDATE;
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
+            sqlSet(true, true, tableInfo, true, ENTITY, ENTITY_DOT),
+            sqlWhereEntityWrapper(true, tableInfo),
+            sqlComment());
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return this.addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+    }
+}

+ 43 - 0
com/baomidou/mybatisplus/core/injector/methods/UpdateById.java

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.injector.methods;
+
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.injector.AbstractMethod;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlSource;
+
+/**
+ * 根据 ID 更新有值字段
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+public class UpdateById extends AbstractMethod {
+
+    @Override
+    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
+        boolean logicDelete = tableInfo.isLogicDelete();
+        SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
+        final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, false);
+        String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
+            sqlSet(logicDelete, false, tableInfo, false, ENTITY, ENTITY_DOT),
+            tableInfo.getKeyColumn(), ENTITY_DOT + tableInfo.getKeyProperty(), additional);
+        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
+        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);
+    }
+}

+ 22 - 0
com/baomidou/mybatisplus/core/injector/methods/package-info.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+/**
+ * 注入 SQL 操作方法相关类
+ *
+ * @author hubin
+ * @since 2018-04-06
+ */
+package com.baomidou.mybatisplus.core.injector.methods;