package com.casic.PgInterface.construction.manager;

import com.casic.PgInterface.construction.domain.PgConRequestMsg;
import com.casic.PgInterface.construction.dto.PgConRequestMsgDto;
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 PgConRequestMsgManager extends HibernateEntityDao<PgConRequestMsg> {

    public Map<String,Object> getPgConRequestMsgDtoList(String buildCompany, String project, int page, int rows){
        Criteria criteria=createCriteria(PgConRequestMsg.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<PgConRequestMsg> pgConRequestMsgList = (List<PgConRequestMsg>)pg.getResult();

            List<PgConRequestMsgDto> pgConRequestMsgDtoList = PgConRequestMsgDto.getPgConRequestMsgDtoList(pgConRequestMsgList);

            if (pgConRequestMsgDtoList == null || pgConRequestMsgDtoList.size() == 0)
            {
                resultMap.put("msg", "没有施工请求信息");
                resultMap.put("code","0");
            }
            else
            {
                resultMap.put("code","200");
                resultMap.put("msg", "施工请求信息获取成功");
            }

            resultMap.put("count",pg.getTotalCount());
            resultMap.put("result",pgConRequestMsgDtoList);
            return resultMap;
        }
        catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

}
