/**
 * Copyright (c) 2020-2038, <NAME> (<EMAIL>).
 * <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>
 * http://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 org.tyuan.service.dao.mapper.customize;

import org.tyuan.service.dao.mapper.OrganizationInstitutionMapper;
import org.tyuan.service.dao.model.custom.COrganizationInstitution;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

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

public interface COrganizationInstitutionMapper extends OrganizationInstitutionMapper, ICacheInfo {

    /**
     * 统计条数及获取最后一个更新的时间
     *
     * @return
     */
    @Override
    @Select("select update_time, b.c total " +
            " from organization_institution, " +
            "  (select count(*) c from organization_institution) as b " +
            " order by update_time desc " +
            " limit 1;")
    @Results({
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "total", property = "total", jdbcType = JdbcType.INTEGER)
    })
    Map getLastUpdateAndCount();


    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table organization_institution
     *
     * @mbggenerated
     */
    @Select({
            "select",
            "id, parent_id, inst_code, inst_name, inst_type, owner_user_id, inst_sort, inst_status ,update_time,remarks ",
            "from organization_institution",
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "parent_id", property = "parentId", jdbcType = JdbcType.BIGINT),
            @Result(column = "inst_code", property = "instCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "inst_name", property = "instName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
            @Result(column = "inst_type", property = "instType", jdbcType = JdbcType.INTEGER),
            @Result(column = "owner_user_id", property = "ownerUserId", jdbcType = JdbcType.BIGINT),
            @Result(column = "inst_sort", property = "instSort", jdbcType = JdbcType.INTEGER),
            @Result(column = "inst_status", property = "instStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
    })
    List<COrganizationInstitution> getAll();
}
