package com.fs.qywx.mapper;

import java.util.List;
import com.fs.qywx.domain.QywxCompany;

import com.fs.qywx.vo.QywxCompanyListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * 企业微信三方应用授权公司Mapper接口
 *
 * @author fs
 * @date 2023-07-24
 */
@Mapper
public interface QywxCompanyMapper
{
    /**
     * 查询企业微信三方应用授权公司
     *
     * @param id 企业微信三方应用授权公司主键
     * @return 企业微信三方应用授权公司
     */
    public QywxCompany selectQywxCompanyById(Integer id);

    /**
     * 查询企业微信三方应用授权公司列表
     *
     * @param qywxCompany 企业微信三方应用授权公司
     * @return 企业微信三方应用授权公司集合
     */
    public List<QywxCompany> selectQywxCompanyList(QywxCompany qywxCompany);

    /**
     * 新增企业微信三方应用授权公司
     *
     * @param qywxCompany 企业微信三方应用授权公司
     * @return 结果
     */
    public int insertQywxCompany(QywxCompany qywxCompany);

    /**
     * 修改企业微信三方应用授权公司
     *
     * @param qywxCompany 企业微信三方应用授权公司
     * @return 结果
     */
    public int updateQywxCompany(QywxCompany qywxCompany);

    /**
     * 删除企业微信三方应用授权公司
     *
     * @param id 企业微信三方应用授权公司主键
     * @return 结果
     */
    public int deleteQywxCompanyById(Integer id);

    /**
     * 批量删除企业微信三方应用授权公司
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteQywxCompanyByIds(Integer[] ids);

    @Update(" update qywx_company set status=-1 where corp_id = #{corp_id} and status=1")
    boolean deleteQywxCompanyByCorpId(String corpId);

    @Select({"<script> " +
            "select q.*,c.company_name,a.name as agentName from qywx_company q " +
            "left join company c on c.company_id = q.company_id " +
            " left join qywx_app a on q.agent_id=a.agent_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null      '> " +
            "and q.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test= 'maps.corpName != null  and maps.corpName !=\"\"    '> " +
            "and q.corp_name like concat('%', #{maps.corpName}, '%')  " +
            "</if>" +
            "<if test = 'maps.status != null      '> " +
            "and q.status =#{maps.status} " +
            "</if>" +
            " order by q.id desc " +
            "</script>"})
    public List<QywxCompanyListVO> selectQywxCompanyListVO(@Param("maps") QywxCompany qywxCompany);

    @Update(" update qywx_company set access_token = #{accessToken} where corp_id = #{corpId} ")
    void updateAccessToken(@Param("corpId") String corpId, @Param("accessToken")String accessToken);

}
