package com.sifang.modules.sys.dao;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.sys.common.entity.FormPartnerSet;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;


@Repository
public class FormPartnerSetDao extends BaseDao<FormPartnerSet> {

    public List<FormPartnerSet> findBySetIds(List<String> setIds,String partner){
        String sql = "from FormPartnerSet where formSetId in (:p1) and partner =:p2";
        Query query = getSession().createQuery(sql).
                setString("p2", partner).
                setParameterList("p1", setIds);
        return query.list();
//        return find("from FormPartnerSet where formSetId in (:p1) and partner =:p2",
//                new Parameter(setIds, partner));
    }

    /**
     * 查询配置
     */
    public FormPartnerSet findOneByFormSetId(String formSetId, String partner) {
        return getByHql("from FormPartnerSet where formSetId = :p1 and partner = :p2", new Parameter(formSetId, partner));
    }

    public void createOne(String formSetId, String partner, String mustFillFlag, String status) {
        FormPartnerSet partnerSet = new FormPartnerSet();
        partnerSet.setFormSetId(formSetId);
        partnerSet.setPartner(partner);
        partnerSet.setLimitFlag("0");
        partnerSet.setMustFillFlag(mustFillFlag);
        partnerSet.setCreateTime(new Date());
        partnerSet.setStatus(status);
        save(partnerSet);
    }
}
