package thyyxxk.webserver.dao.his.reports;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.reports.reportQueryCenter.ReportForms;

import java.util.List;

@Mapper
public interface ReportQueryCenterDao extends BaseMapper<ReportForms> {

    @Select("select a.id, name, page_json, type, parent_id from " +
            "report_forms a, report_forms_rules b  " +
            "where del_flag = 0 and a.id = b.rule_id and b.user_code =#{userCode}  ")
    List<ReportForms> selectReportForms(String userCode);

    @Select("select  id, name, page_json, type, parent_id from " +
            " report_forms " +
            " where del_flag = 0   ")
    List<ReportForms> selectReportFormsAll();


    @Update("update report_forms set del_flag = 1 where id = #{id};" +
            "update report_forms set del_flag = 1 where parent_id = #{id}")
    void del(String id);

    @Update("update report_forms set parent_id = #{parentId} where id = #{id} ")
    void updateParentById(String id, String parentId);

    @Select("delete  report_forms_rules where user_code = #{userCode} ")
    void delRules(String userCode);

    @Insert("insert into report_forms_rules (user_code, rule_id)  values (#{code} , #{id})")
    void insertRules(String code, String id);

    @Select("select rule_id from report_forms_rules where user_code = #{userCode}")
    List<String> getRulesByCode(String userCode);

}
