PublicMapper.java 5.3 KB
package com.ruoyi.system.mapper;

import com.ruoyi.system.dto.PublicSQL;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 公用mapper
 */
@Component
public interface PublicMapper {
    /**
     * 添加对象
     */
    @InsertProvider(type = PublicSQL.class, method = "insert")
    int insert(Object object);

    /**
     * 指定表名添加
     */
    @InsertProvider(type = PublicSQL.class, method = "insertToTable")
    int insertToTable(Object object,String tableName);

    /**
     * 添加对象集合
     */
    @InsertProvider(type = PublicSQL.class, method = "insertAll")
    int insertAll(List<?> list);

    /**
     * 指定表名添加对象集合
     */
    @InsertProvider(type = PublicSQL.class, method = "insertAllToTable")
    int insertAllToTable(@Param("list")List<?> list,@Param("tableName")String tableName);

    /**
     * 更新对象不为空的属性
     * @param object
     * @param whereFieldNames
     */
    @UpdateProvider(type = PublicSQL.class, method = "updateObject")
    int updateObject(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames);

    @UpdateProvider(type = PublicSQL.class, method = "updateObject")
    int updateObjectByTable(@Param("object") Object object, @Param("whereFieldNames") String whereFieldNames, @Param("tablename") String tablename);

    /**
     * 自定义sql更新
     * @param sql
     */
    @UpdateProvider(type = PublicSQL.class, method = "updateBySql")
    int updateBySql(String sql);

    /**
     * 查询 通过条件查询
     * @param clas
     * @param idName
     * @param values
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObject")
    <T> T  getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values);

    @SelectProvider(type = PublicSQL.class, method = "selectCountBySql")
    Long selectCountBySql(@Param("sql") String sql);
    /**
     * 查询 通过条件查询
     * @param clas
     * @param idName
     * @param values
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObject")
    Map<String,Object> getObjectForTableName(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName);

    /**
     * 查询 通过条件查询单个指定项目
     * @param clas 類型
     * @param select 查詢結果
     * @param idName 主鍵名稱
     * @param values 主鍵值
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObject")
    Map<String,Object> getObjectSelectTableName(@Param("class") Class<?> clas, @Param("select") String select, @Param("idName") String idName, @Param("values") String values, @Param("tableName") String tableName);

    /**
     * 查询list
     * @param object
     * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间
     * @param order
     * @param pagetSize
     * @param pageNo
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObjectList")
    List<Map<String,Object>> getObjectList(@Param("object") Object object, @Param("selectStr") String selectStr, @Param("whereMap") Map<String, String> whereMap, @Param("order") String order, @Param("pageSize") Integer pagetSize, @Param("pageNo") Integer pageNo);

    /**
     * 查詢totle
     * @param object
     * @param whereMap 如果是时间,whereMap里面对应的字段比较符为time,同时添加一个end_字段名的值 表示是结束时间
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObjectListTotle")
    Long getObjectListTotle(@Param("object") Object object, @Param("whereMap") Map<String, String> whereMap);

    /**
     * 通过条件删除对象
     * @param oClass
     * @param map
     */
    @UpdateProvider(type = PublicSQL.class, method = "deleteObjectByContent")
    int deleteObjectByContent(@Param("objectCalss") Class<?> oClass, @Param("map") Map<String, String> map);

    /**
     * 自定义sql语句查询list
     * @param sql
     * @return
     */
    @SelectProvider(type = PublicSQL.class, method = "getObjectListBySQL")
    List<Map<String,Object>> getObjectListBySQL(@Param("sql") String sql);
    /**
     * 添加或更新对象列表
     * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`);
     * @param objectlist 对象列表
     * @return
     */
    @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObjectList")
    int saveOrUpdateObjectList(List<Object> objectlist);

    /**
     * 添加或更新对象
     * INSERT INTO test(`in1`,`str1`) VALUES ('1','1');
     * @param object 对象
     * @return
     */
    @UpdateProvider(type = PublicSQL.class, method = "saveOrUpdateObject")
    int saveOrUpdateObject(Object object);

    /**
     * 通过id删除数据
     * @return
     */
    @UpdateProvider(type = PublicSQL.class, method = "deleteObjectById")
    int deleteObjectById(@Param("objectCalss") Class<?> oClass, @Param("id") String id);

    @Options(useGeneratedKeys = false)
    @InsertProvider(type = PublicSQL.class, method = "updateBySql")
    int insertIntoBySql(@Param("sql") String sql);
}