package jj.tech.paolu.repository.mybatis.dao;

import static jj.tech.paolu.repository.mybatis.dao.support.SysOrgDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import jakarta.annotation.Generated;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import jj.tech.paolu.repository.mybatis.entity.SysOrg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface SysOrgMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<SysOrg>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    BasicColumn[] selectList = BasicColumn.columnList(id, pid, status, org_type);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.7051823+08:00", comments="Source Table: yx..sys_org")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="SysOrgResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="pid", property="pid", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="org_type", property="org_type", jdbcType=JdbcType.VARCHAR)
    })
    List<SysOrg> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("SysOrgResult")
    Optional<SysOrg> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int deleteByPrimaryKey(String id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int insert(SysOrg row) {
        return MyBatis3Utils.insert(this::insert, row, sysOrg, c ->
            c.map(id).toProperty("id")
            .map(pid).toProperty("pid")
            .map(status).toProperty("status")
            .map(org_type).toProperty("org_type")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int insertMultiple(Collection<SysOrg> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, sysOrg, c ->
            c.map(id).toProperty("id")
            .map(pid).toProperty("pid")
            .map(status).toProperty("status")
            .map(org_type).toProperty("org_type")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int insertSelective(SysOrg row) {
        return MyBatis3Utils.insert(this::insert, row, sysOrg, c ->
            c.map(id).toPropertyWhenPresent("id", row::getId)
            .map(pid).toPropertyWhenPresent("pid", row::getPid)
            .map(status).toPropertyWhenPresent("status", row::getStatus)
            .map(org_type).toPropertyWhenPresent("org_type", row::getOrg_type)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default Optional<SysOrg> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default List<SysOrg> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default List<SysOrg> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default Optional<SysOrg> selectByPrimaryKey(String id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.70618+08:00", comments="Source Table: yx..sys_org")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, sysOrg, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.7071804+08:00", comments="Source Table: yx..sys_org")
    static UpdateDSL<UpdateModel> updateAllColumns(SysOrg row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(row::getId)
                .set(pid).equalTo(row::getPid)
                .set(status).equalTo(row::getStatus)
                .set(org_type).equalTo(row::getOrg_type);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.7071804+08:00", comments="Source Table: yx..sys_org")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(SysOrg row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(row::getId)
                .set(pid).equalToWhenPresent(row::getPid)
                .set(status).equalToWhenPresent(row::getStatus)
                .set(org_type).equalToWhenPresent(row::getOrg_type);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.7071804+08:00", comments="Source Table: yx..sys_org")
    default int updateByPrimaryKey(SysOrg row) {
        return update(c ->
            c.set(pid).equalTo(row::getPid)
            .set(status).equalTo(row::getStatus)
            .set(org_type).equalTo(row::getOrg_type)
            .where(id, isEqualTo(row::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2024-09-27T03:01:29.7071804+08:00", comments="Source Table: yx..sys_org")
    default int updateByPrimaryKeySelective(SysOrg row) {
        return update(c ->
            c.set(pid).equalToWhenPresent(row::getPid)
            .set(status).equalToWhenPresent(row::getStatus)
            .set(org_type).equalToWhenPresent(row::getOrg_type)
            .where(id, isEqualTo(row::getId))
        );
    }
}