TccExternalService.java 3.96 KB
package com.bsth.data.schedule.external;

import com.bsth.common.ResponseCode;
import com.bsth.controller.realcontrol.dto.ChangePersonCar;
import com.bsth.controller.realcontrol.dto.DftzAndDestroy;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.websocket.handler.SendUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 对停车场开放的班次调度服务
 * Created by panzhao on 2018/3/22.
 */
@Component
public class TccExternalService {

    Logger logger = LoggerFactory.getLogger(TccExternalService.class);

    @Autowired
    DayOfSchedule dayOfSchedule;

    @Autowired
    ScheduleRealInfoService scheduleRealInfoService;

    @Autowired
    SendUtils sendUtils;

    /**
     * Departure time adjustment
     *
     * @param dad
     * @return
     */
    public Map<String, Object> dftz(DftzAndDestroy dad) {
        Map<String, Object> rs = new HashMap();
        rs.put("status", ResponseCode.ERROR);
        try {
            List<ScheduleRealInfo> updateList = new ArrayList<>();//要刷新的班次
            ScheduleRealInfo sch = dayOfSchedule.get(dad.getDftzId());
            if (null == sch) {
                rs.put("msg", "班次已经不存在了!");
                return rs;
            }

            if (!sch.getBcType().equals("out")) {
                rs.put("msg", "只能操作出场班次!");
                return rs;
            }

            //调整待发时间
            scheduleRealInfoService.outgoAdjust(sch.getId(), dad.getRemarks(), dad.getNewTimeStr(), sch.getBcType(), "4", dad.getUserId());
            updateList.add(sch);

            //需要烂班的班次
            if (StringUtils.isNotEmpty(dad.getDestroyIdx())) {
                Map<String, Object> dMap =
                        scheduleRealInfoService.destroy(dad.getDestroyIdx(), dad.getRemarks(), dad.getReason(), dad.getUserId());


                updateList.addAll((Collection<? extends ScheduleRealInfo>) dMap.get("ts"));
            }

            //通知调度客户端更新班次信息
            sendUpdate2Page(updateList);

            rs.put("status", ResponseCode.SUCCESS);
            rs.put("t", sch);
        } catch (Exception e) {
            rs.put("msg", "内部调度服务接口出现异常!");
            logger.error("", e);
        }
        return rs;
    }

    /**
     * 换人换车
     *
     * @param cpcs
     * @return
     */
    public Map<String, Object> hrhc(List<ChangePersonCar> cpcs,String tccCode, String userId) {
        Map<String, Object> rs = new HashMap();
        rs.put("status", ResponseCode.ERROR);
        try {
            rs = scheduleRealInfoService.multi_tzrc(cpcs, userId);

            //通知调度客户端更新班次信息
            sendUpdate2Page(new ArrayList<ScheduleRealInfo>((Set)rs.get("ts")));

            //返回更新结果集中指定停车场的进出场班次
            Set<ScheduleRealInfo> ts = (Set<ScheduleRealInfo>) rs.get("ts");
            List<ScheduleRealInfo> list = new ArrayList<>();
            for(ScheduleRealInfo sch : ts){
                if((sch.getBcType().equals("out") && sch.getQdzCode().equals(tccCode))
                        || (sch.getBcType().equals("in") && sch.getZdzCode().equals(tccCode)))
                    list.add(sch);
            }
            rs.put("list", list);
            rs.remove("ts");
        } catch (Exception e) {
            rs.put("msg", "服务器出现异常!");
            logger.error("", e);
        }
        return rs;
    }


    public void sendUpdate2Page(List<ScheduleRealInfo> list) {
        sendUtils.refreshSch(list);
    }
}