#
vincentlu
3 天以前 a493cc741f9c631991979822401f30b4db8816a1
zy-acs-manager/src/main/java/com/zy/acs/manager/core/integrate/wms/OpenController.java
@@ -4,7 +4,9 @@
import com.zy.acs.framework.common.R;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.common.constant.Constants;
import com.zy.acs.manager.common.domain.TaskBoolDto;
import com.zy.acs.manager.core.integrate.dto.OpenBusCancelParam;
import com.zy.acs.manager.core.integrate.dto.OpenBusCancelResult;
import com.zy.acs.manager.core.integrate.dto.OpenBusSubmitParam;
import com.zy.acs.manager.core.service.MainService;
import com.zy.acs.manager.manager.entity.Bus;
@@ -13,6 +15,7 @@
import com.zy.acs.manager.manager.service.TaskService;
import com.zy.acs.manager.system.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -22,6 +25,7 @@
/**
 * Created by vincent on 2023/6/12
 */
@Slf4j
@Api(tags = "Open Api")
@RestController
@RequestMapping("/api/open")
@@ -41,29 +45,36 @@
        return R.ok("generate tasks success");
    }
    @PostMapping("/bus/cancel")
    @PostMapping("/task/cancel")
    @OperationLog("cancel task from open api")
    public R cancel(@RequestBody OpenBusCancelParam param) {
        if (Cools.isEmpty(param.getBatchNo())) {
            return R.error("batchNo is empty");
        }
        if (Cools.isEmpty(param.getTasks())) {
            return R.error("tasks is empty");
        }
        Long busId = null;
        if (!Cools.isEmpty(param.getBatchNo())) {
            Bus bus = busService.selectByBusNo(param.getBatchNo());
            if (null != bus) {
                busId = bus.getId();
            }
        } else {
//            return R.error("batch_no is empty");
        Bus bus = busService.selectByBusNo(param.getBatchNo());
        if (null == bus) {
            return R.error("batchNo is not exist");
        }
        OpenBusCancelResult result = new OpenBusCancelResult();
        result.setBatchNo(param.getBatchNo());
        for (String taskNo : param.getTasks()) {
            Task task = taskService.selectBySeqNum(busId, taskNo);
            Task task = taskService.selectBySeqNum(bus.getId(), taskNo);
            if (null == task) {
                result.getTasks().add(new TaskBoolDto(taskNo, Boolean.FALSE,  taskNo + " is not exist"));
                continue;
            }
            taskService.cancel(task.getId(), null, Constants.UPLINK);
            Boolean cancel = false;
            try {
                cancel = taskService.cancel(task.getId(), null, Constants.UPLINK);
            } catch (Exception e) {
                log.error("failed to cancel task {}", taskNo, e);
            }
            result.getTasks().add(new TaskBoolDto(taskNo, cancel));
        }
        return R.ok("cancel tasks success");
        return R.ok("cancel tasks success").add(result);
    }
}