TaskFinishServiceImpl.java 3.45 KB
package com.huaheng.api.wcs.service.taskFinish;

import com.huaheng.api.acs.service.AgvTaskCSService;
import com.huaheng.api.wcs.domain.TaskFinishDomain;
import com.huaheng.api.wcs.service.emptyOutHandle.EmptyOutHandleService;
import com.huaheng.api.wcs.service.overrideHandle.OverrideHandleService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class TaskFinishServiceImpl implements TaskFinishService {

    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private EmptyOutHandleService emptyOutHandleService;
    @Resource
    private OverrideHandleService overrideHandleService;
    @Resource
    private ContainerService containerService;
    @Resource
    private LocationService locationService;
    @Resource
    private AgvTaskCSService agvTaskService;

    //任务完成
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult completeTaskByWCS(TaskFinishDomain taskFinishDomain) {
        AjaxResult ajaxResult = new AjaxResult();
        if (StringUtils.isEmpty(taskFinishDomain.getTaskNo())) {
            return AjaxResult.error("任务号为空");
        }
        if (StringUtils.isEmpty(taskFinishDomain.getWarehouseCode())) {
            return AjaxResult.error("仓库号为空");
        }
        TaskHeader taskHeader = taskHeaderService.getById(taskFinishDomain.getTaskNo());
        if (taskHeader == null) {
            return AjaxResult.success("wms系统没有此任务号:" + taskFinishDomain.getTaskNo());
        }
        String warehouseCode = taskHeader.getWarehouseCode();
        //1、空出处理
        if (taskFinishDomain.getIsEmptyOut() == 1) {
            taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
            boolean result = taskHeaderService.updateById(taskHeader);
            if (!result) {
                return AjaxResult.error("空出处理,修改任务状态失败");
            }
            return AjaxResult.success(result);
        }


        String[] weight = new String[1];
        if (StringUtils.isNotEmpty(taskFinishDomain.getWeight())) {
            weight = Convert.toStrArray(taskFinishDomain.getWeight());
        }

        //任务完成
//        try{
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        ajaxResult = taskHeaderService.completeTaskByWMS(Convert.toIntArray(taskFinishDomain.getTaskNo()), weight);

        boolean foldFlag = taskFinishDomain.isFoldFlag();
        if (foldFlag) {
            String containerCode = taskHeader.getContainerCode();
            String locationCode = taskHeader.getFromLocation();
            containerService.updateLocationCodeAndStatus(containerCode,
                    "", QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
            locationService.updateContainerCodeAndStatus(locationCode, "",
                    QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
        }
        return ajaxResult;
    }
}