GreeDeviceController.java 5.9 KB
package com.myproject.webapp.controller.webService;

import com.google.common.collect.Lists;
import com.myproject.bean.qisda.InquiryShelfBean;
import com.myproject.bean.qisda.ResultBean;
import com.myproject.bean.qisda.ShelfInfo;
import com.myproject.bean.qisda.ShelfLoc;
import com.myproject.bean.update.DataLog;
import com.myproject.bean.update.Storage;
import com.myproject.bean.update.qisda.OutInfo;
import com.myproject.util.StorageConstants;
import com.myproject.webapp.controller.qisda.util.OutInfoCache;
import org.apache.cxf.jaxws.handler.types.CString;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import org.apache.poi.util.Internal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/rest/api/dcs/device")
public class GreeDeviceController {
    @Autowired
    protected ITaskService taskService;

    @Autowired
    private OutInfoCache outInfoCache;
    protected final static Logger log = LogManager.getLogger(QisdaDeviceController.class);

    /**
     * 获取当前任务数及料架的剩余空位
     * 参数:rfids 料架rfid列表,逗号分割,未发送rfids只返回当前剩余任务数量
     */
    @RequestMapping(value = "/getShelfEmptySlot")
    @ResponseBody
    public Object getTaskInfo(HttpServletRequest request) {
        String rfids = request.getParameter("rfids");
        try{

            List<DataLog> allTasks = taskService.getAllTasks();
            Map<String,Integer> hSerialTaskMap = new HashMap<>();
            for (DataLog task : allTasks) {
                if (!task.isFinished() && !task.isCancel() && task.isCheckOutTask()) {
                    String hSerial = task.getAppendInfo().gethSerial();
                    Integer taskCount = hSerialTaskMap.get(hSerial);
                    if(taskCount == null){
                        taskCount = 0;
                    }
                    taskCount ++;
                    hSerialTaskMap.put(hSerial,taskCount);
                }
            }
            String hSerial = QisdaCache.getCurrentOrderHSerial();
            List<String> usedRfidList = InquiryShelfBean.getUsedRfidList(hSerial);
            Map<String,Integer> rfidMap = new HashMap<>();
            if (!Strings.isBlank(rfids)) {
                Integer emptyPos=0;
                for (String rfid : rfids.split(",")) {
                    ShelfInfo shelfInfo = InquiryShelfBean.findShelfByRealRfid(rfid);
                    if(shelfInfo != null){
                        Map<Integer, ShelfLoc> locMap = shelfInfo.getLocMap();
                        for (ShelfLoc shelfLoc : locMap.values()) {
                            if(shelfLoc.isEmpty()){
                                emptyPos++;
                            }
                        }
                    }else{
                        //空料架
                        emptyPos = 100;
                    }
                    Integer hSerialTaskCount = hSerialTaskMap.get(shelfInfo.gethSerial());
                    if(hSerialTaskCount == null){
                        emptyPos = 0;
                    }
                    rfidMap.put(rfid,emptyPos);
                }
            }
            return ResultBean.newOkResult(rfidMap);

        }catch(Exception e){
            log.error("获取剩余任务数出错:rfids="+rfids,e);
            return ResultBean.newErrorResult(500,e.getMessage());
        }
    }

    /**
     * 获取rfid目的地出错
     * 参数:rfid  料架rfid
     */
    @RequestMapping(value = "/getRfidTargetP")
    @ResponseBody
    public Object getRfidTargetP(HttpServletRequest request) {
        String rfid = request.getParameter("rfid");
        try {
            if (!Strings.isBlank(rfid)) {
                ShelfInfo shelf = InquiryShelfBean.findShelfByRealRfid(rfid);
                if (shelf != null) {
                    String hSerial = shelf.gethSerial();

                    OutInfo outInfo = outInfoCache.getOutInfoFromCache(hSerial);
                    if (outInfo != null) {
                        String line= outInfo.getLine();
                        log.error("获取rfid目的地成功:rfid=" + rfid + ",line=" + line + "");
                        return ResultBean.newOkResult(line);
                    } else {
                        log.error("获取rfid目的地失败:rfid=" + rfid + ",hSerial=" + hSerial + ",未找到工单信息");
                        return ResultBean.newErrorResult(3001,"未找到工单信息");
                    }
                } else {
                    log.error("获取rfid目的地失败:rfid=" + rfid + ",未找到料架信息");
                    return ResultBean.newErrorResult(3002,"未找到料架信息");
                }
            }
        } catch (Exception e) {
            log.error("获取rfid目的地出错:rfid=" + rfid, e);
            return ResultBean.newErrorResult(500,e.getMessage());
        }
        return ResultBean.newErrorResult(3003,"位置获取失败");
    }
    /**
     * 料架放上AGV时,根据RFID清理料架的缓存信息,使料架可以重复使用
     */
    @RequestMapping(value = "/agvRemoveRfid")
    @ResponseBody
    public ResultBean agvRemoveRfid(HttpServletRequest request){
        String realRfid = request.getParameter("rfid");
        log.info("料架放上AGV时,清理["+realRfid+"]的缓存信息");
        if(Strings.isNotBlank(realRfid)){
            InquiryShelfBean.agvRemoveRfid(realRfid);
        }
        return ResultBean.newOkResult("料架放上AGV时,清理["+realRfid+"]的缓存信息成功");
    }
}