/**
 *
 */
package com.sifang.modules.flowable.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import org.springframework.stereotype.Repository;
import com.sifang.modules.flowable.entity.ProcessDefLatest;

import java.util.List;

/**
 * 信息DAO接口
 * @author Ivan
 * @version 2023-04-11
 */
@Repository
public class ProcessDefLatestDao extends BaseDao<ProcessDefLatest> {

    public ProcessDefLatest getByKey(String key) {
        return getByHql("from ProcessDefLatest l  WHERE l.keyValue =:p1 ", new Parameter(key));
    }

    public List<Record> getAllFields(String formId) {
        String sql = " SELECT f.name,f.code FROM `crm_process_form_field` f WHERE f.form_id=?  ";
        return Db.find(sql, formId);
    }

    public Record getLatest(String formId){
        return Db.findFirst(" SELECT d.id,d.key_value,d.status,d.name,d.form_id FROM `crm_process_def_latest` l LEFT JOIN `crm_process_def` d ON d.id=l.process_def_id WHERE d.form_id=? ",formId);
    }

}
