package com.casic.PgInterface.construction.manager;

import com.casic.PgInterface.construction.domain.PgConWorkOrder;
import com.casic.PgInterface.construction.dto.PgConWorkOrderDto;
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 PgConWorkOrderManager extends HibernateEntityDao<PgConWorkOrder> {

    public  Map<String, Object> getPgConWorkOrderDtoList(String taskCompany,String taskName,String taskPlace,int page,int rows){

        Map<String, Object> resultMap = new HashMap<>();
        String msg="";

        Criteria criteria=createCriteria(PgConWorkOrder.class);

        try {
            if (StringUtils.isNotBlank(taskCompany))
                criteria.add(Restrictions.like("TASK_COMPANY", "%" + taskCompany + "%"));
            if (StringUtils.isNotBlank(taskName))
                criteria.add(Restrictions.like("TASK_NAME", "%" + taskName + "%"));
            if (StringUtils.isNotBlank(taskPlace))
                criteria.add(Restrictions.like("TASK_PLACE", "%" + taskPlace + "%"));

            Page pg = pagedQuery(criteria, page, rows);

            List<PgConWorkOrder> pgConWorkOrderList = (List<PgConWorkOrder>)pg.getResult();

            List<PgConWorkOrderDto> pgConWorkOrderDtoList = PgConWorkOrderDto.getPgConWorkOrderListDto(pgConWorkOrderList);

            if (pgConWorkOrderDtoList == null || pgConWorkOrderDtoList.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",pgConWorkOrderDtoList);
            return resultMap;
        }
        catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

}
