package com.zg.project.wisdom.service.impl;

import com.zg.common.utils.DateUtils;
import com.zg.project.wisdom.domain.WcsTaskResult;
import com.zg.project.wisdom.mapper.WcsTaskResultMapper;
import com.zg.project.wisdom.service.IWcsTaskResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WcsTaskResultServiceImpl implements IWcsTaskResultService {

    @Autowired
    private WcsTaskResultMapper wcsTaskResultMapper;

    @Override
    public void handleWcsCallback(WcsTaskResult dto) {
        String taskId = dto.getTaskId();

        WcsTaskResult result = new WcsTaskResult();
        result.setTaskId(taskId);
        result.setTaskStatus(dto.getTaskStatus());
        result.setMsg(dto.getMsg());
        result.setCreateBy("wcs");
        result.setCreateTime(DateUtils.getNowDate());
        result.setIsDelete("0");

        wcsTaskResultMapper.insertWcsTaskResult(result);
    }

    @Override
    public boolean checkTaskStatusExists(String taskId) {
        return wcsTaskResultMapper.countByTaskId(taskId) > 0;
    }
}
