package cn.estsh.i3plus.core.apiservice.serviceimpl.base;

import cn.estsh.i3plus.core.api.iservice.base.IReportService;
import cn.estsh.i3plus.core.apiservice.dao.IReportDao;
import cn.estsh.i3plus.pojo.base.tool.HqlPack;
import cn.estsh.i3plus.pojo.model.report.TemplateModel;
import org.hibernate.QueryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : Adair Peng
 * @CreateDate : 2019-01-20 16:06
 * @Modify:
 **/
@Service
public class ReportService implements IReportService {

    private Logger LOGGER = LoggerFactory.getLogger(ReportService.class);

    @Autowired
    private IReportDao reportDao;


    @Override
    public void checkReportHQL(String hql) {
        LOGGER.info("报表 HQL 注入检查:{}",hql);
        // HQL 非法入侵检查
        HqlPack.getSafeParam(hql);
    }

    @Override
    public List selectTemplateModel(TemplateModel model) throws Exception{
        LOGGER.info("报表执行 model :{}",model);
        return reportDao.findByHqlObjects(model.getHql(), model.getParamName(), model.getParamValue());
    }
}
