ScheduleRealInfoServiceImpl.java 3.55 KB
package com.bsth.service.impl;

import com.bsth.entity.LineConfig;
import com.bsth.entity.ScheduleRealInfo;
import com.bsth.entity.result.CalcWaybill;
import com.bsth.repository.ScheduleRealInfoRepository;
import com.bsth.service.LineConfigService;
import com.bsth.service.ScheduleRealInfoService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.bsth.entity.ChildTaskPlan;

/**
 * Created by panzhao on 2017/7/27.
 */
@Service
public class ScheduleRealInfoServiceImpl implements ScheduleRealInfoService {

    @Autowired
    ScheduleRealInfoRepository scheduleRealInfoRepository;

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    LineConfigService lineConfigService;

    Logger logger = LoggerFactory.getLogger(this.getClass());

    private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
            fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"),
            fmtHHmm = DateTimeFormat.forPattern("HH:mm");

    private final static long DAY_TIME = 1000 * 60 * 60 * 24L;

    @Override
    public List<CalcWaybill> findAll(String rq,String lineCode) {
        List<ScheduleRealInfo> list = scheduleRealInfoRepository.findAll(rq,lineCode);
        String sql ="select r.j_gh ,r.s_gh,r.cl_zbh,r.xl_bm, r.lp_name FROM"
        		+ "  bsth_c_s_sp_info_real r  where  "
        		+ " r.schedule_date_str='"+rq+"' and r.xl_bm = '"+lineCode+"'"
        		+ " GROUP BY r.j_gh,r.xl_bm,r.lp_name ";

		List<Map<String, String>> listMap = jdbcTemplate.query(sql, new RowMapper<Map<String, String>>() {
			@Override
			public Map<String, String> mapRow(ResultSet arg0, int arg1) throws SQLException {
				Map<String, String> c = new HashMap<String,String>();
				c.put("jGh", arg0.getString("j_gh"));
				c.put("sGh", arg0.getString("s_gh")==null?"":arg0.getString("s_gh"));
				c.put("clZbh", arg0.getString("cl_zbh"));
				c.put("xlBm", arg0.getString("xl_bm"));
				c.put("lpName", arg0.getString("lp_name"));
				return c;
			}
		});
        for (int i = 0; i < listMap.size(); i++) {
			Map<String, String> m=listMap.get(i);
			String jGh=m.get("jGh");
			String sGh=m.get("sGh");
			String clZbh=m.get("clZbh");
			String xlBm=m.get("xlBm");
			String lpName=m.get("lpName");
			//所有数据排班数据
			List<ScheduleRealInfo> list_=new ArrayList<ScheduleRealInfo>();
			//执行了的班次的排班数据
			List<ScheduleRealInfo> lists_=new ArrayList<ScheduleRealInfo>();
			for (int j = 0; j < list.size(); j++) {
				ScheduleRealInfo s=list.get(j);
				if(jGh.equals(s.getjGh())
						&& sGh.equals(s.getsGh()==null?"":s.getsGh())
						&& clZbh.equals(s.getClZbh())
						&& xlBm.equals(s.getXlBm())
						&& lpName.equals(s.getLpName())){
					
					list_.add(s);
					
					Set<ChildTaskPlan> cts = s.getcTasks();
		            if(cts != null && cts.size() > 0){
		            	lists_.add(s);
		            }else{
			            if(s.getZdsjActual()!=null 
			            		&& s.getFcsjActual() !=null){
			            	lists_.add(s);
			            }
		            }
				}
			}
			
			
		}
        return null;
    }

}