package com.crunii.micro.service.sysmgr.jdbc;

import com.crunii.micro.common.utils.SqlUtil;
import com.crunii.micro.domain.common.jdbc.BaseJdbcTemplate;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.service.sysmgr.dto.sysmgr.FrequentVisitMenuRspDTO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author gongsongtao
 * @date 2023/9/18 16:18
 */
@Repository
public class FrequentVisitMenuJdbcDao {

    @Resource(name = "mainJT")
    protected BaseJdbcTemplate JT;


    public List<FrequentVisitMenuRspDTO> findFrequentVisitMenu(String scope,Worker worker){
        List<Object>parms=new ArrayList<>();
        String sql=" select b.menu_code,b.menu_name,b.menu_url,a.total,a.login_id,b.icon" +
                " from (select login_id,menu_code,count(1) as total from tsm_worker_menu_visit where login_id=? and scope=? group by menu_code,login_id order by total desc limit 12) a " +
                " left join tsm_menu b on a.menu_code=b.menu_code" +
                " where b.menu_code in (select menu_code from tsm_role_menu a left join tsm_worker_role b on a.role_id=b.role_id where b.login_id=?)" +
                " order by total desc";
        parms.add(worker.getLoginId());
        parms.add(scope);
        parms.add(worker.getLoginId());
        return JT.queryForBeans(FrequentVisitMenuRspDTO.class,sql,parms.toArray());
    }
}
