TaskByWcsImpl.java 2.11 KB
package com.huaheng.api.wcs.service.taskByWcs;

import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.Date;

@Service
public class TaskByWcsImpl implements TaskByWcs{
    @Autowired
    private TaskHeaderService taskHeaderService;
    @Autowired
    private TaskAssignService taskAssignService;
    public static String platform = "wms";

    private static final Logger
        logger = LoggerFactory.getLogger(TaskAssignService.class);
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult taskByWcs(String containerCode) {
        AjaxResult result = null;
        try {
            result = taskHeaderService.createEmptyIn(containerCode);
            if(result.getCode()==200){
                TaskHeader task=taskHeaderService.getById((Integer) result.getData());
                taskAssignService.wcsTaskAssign(task);
                //修改任务头表
                task.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
                task.setStartPickDateTime(new Date());   //生成时间
                task.setLastUpdated(new Date());
                task.setLastUpdatedBy(ShiroUtils.getLoginName());
                taskHeaderService.saveOrUpdate(task);
                return AjaxResult.success("下发成功");
            }
        } catch (Exception e){
            logger.info("手动回滚:{}"+e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error("任务生成失败");
        }
        return result;
    }
}