package com.sifang.modules.sunshine.SystemSetting.dao;

import com.sifang.modules.sunshine.SystemSetting.entity.ProjectPcd;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.common.persistence.Parameter;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class ProjectPcdDao extends BaseDao<ProjectPcd> {

    public List<ProjectPcd> findListByProjectId(String projectId) {
        return find("FROM ProjectPcd WHERE projectId = :p1 AND status = '0' ORDER BY createTime,sort", new Parameter(projectId));
    }

    public void deleteProductArea  (String projectId) {
        SQLQuery sqlQuery = getSession().createSQLQuery("DELETE FROM crm_project_pcd WHERE project_id=:projectId");
        sqlQuery.setParameter("projectId", projectId);
        sqlQuery.executeUpdate();
    }

    public int changeAreaStatus(String projectId) {
        SQLQuery sqlQuery = getSession().createSQLQuery("UPDATE crm_project_pcd SET status='1' WHERE project_id= :projectId  ");
        sqlQuery.setParameter("projectId", projectId);
        int count = sqlQuery.executeUpdate();
        return count;
    }
}
