package com.casic.PgInterface.construction.manager;

import com.casic.PgInterface.construction.domain.PgConRemoveMsg;
import com.casic.PgInterface.construction.domain.PgConRequestMsg;
import com.casic.PgInterface.construction.dto.PgConRemoveMsgDto;
import com.casic.PgInterface.core.hibernate.HibernateEntityDao;
import com.casic.PgInterface.core.page.Page;
import com.casic.PgInterface.core.util.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PgConRemoveMsgManager  extends HibernateEntityDao<PgConRemoveMsg> {

    public Map<String,Object> getPgConRemovetMsgDtoList(String buildCompany, String project,int page,int rows){
        Criteria criteria=createCriteria(PgConRemoveMsg.class);
        Map<String,Object> resultMap=new HashMap<>();

        try {
            if (StringUtils.isNotBlank(buildCompany))
                criteria.add(Restrictions.like("BUILD_COMPANY", "%" + buildCompany + "%"));
            if (StringUtils.isNotBlank(project))
                criteria.add(Restrictions.like("PROJECT", "%" + project + "%"));

            Page pg = pagedQuery(criteria, page, rows);
            List<PgConRemoveMsg> pgConRemoveMsgList = (List<PgConRemoveMsg>)pg.getResult();

            List<PgConRemoveMsgDto> pgConRemoveMsgDtoList = PgConRemoveMsgDto.getPgConRemoveMsgDtoList(pgConRemoveMsgList);

            if (pgConRemoveMsgDtoList == null || pgConRemoveMsgDtoList.size() == 0)
            {
                resultMap.put("msg", "没有施工删除信息");
                resultMap.put("code","0");
            }
            else{
                resultMap.put("code","200");
                resultMap.put("msg", "施工删除信息获取成功");
            }
                return resultMap;
        }
        catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

}
